[Qt-interest] selection / focus issue with QTableView

Tony Rietwyk tony.rietwyk at rightsoft.com.au
Sun Dec 21 10:30:07 CET 2008


Darrik wrote:

> Greetings (seasonal or otherwise), list!
> 
> I have a subclassed AbstractItemModel, a QTableView, and a QLineEdit 
> connected in such a way that the user types a search query 
> string in the 
> QLineEdit and presses enter, the model does a search, and the table 
> displays the results.  Pretty standard.  Everything functions 
> as expected.
> 
> What I want to happen is that when the model populates, I 
> want the table 
> view to automatically get focus and select the first row, 
> such that the 
> user can easily use the arrow keys to navigate between rows.
> 
> I've connected the model's dataChanged() signal to a slot in 
> my window. 
>   In that slot I attempt to call selectRow(0) on the view and 
> setFocus().  This does not work from that slot.  It works outside the 
> slot, but when called from the slot connected to 
> dataChanged(), it does 
> not work.
> 
> Has anyone else experienced this?  Is there a better way to 
> do this?  Is 
> there a reason it shouldn't function when called from this slot?
> 
> Any help would be appreciated.
> 
> Cheers,
> Darrik

Hi Darrik, 

I've had something similar, when popping up an error message during item
selection changes. In this case, I posted a message to reposition to the
original failing row. 

You can also try using a zero timer connected to a slot. Please let me know
the result if you do. 

Hope that helps, 

Tony Rietwyk




More information about the Qt-interest-old mailing list