PDA

View Full Version : Solved-Select first row after QTableView is created and make it active?



adutzu89
30th January 2014, 13:47
I have a table made with QTableView and at it's creation I select the first row, it works, the issue is that the selected row is inactive,meaning I cannot navigate with direction keys through the rows until I click on one.

I also have a signal which is emited when I press the return key, which if I trigger it the signal will emit and after that if I press long on down key it starts to navigate.

I tried using
selectRow(),
setCurrentIndex() from inside the constructor,tried making a function which I trigger after the table was created, also tried using
QTimer::SingleShot() and even
setFocus() on table after it is constructed but still the selected row remains inactive.

Any thing else to try?

Finally figured out, I focused the wrong way. I had multiple widgets inside the widget that contain the table and instead of focusing on the table I focused on the widget that contains the table.

jijoadoor71
15th May 2014, 16:15
I have a single QTableView(model based).I need to give focus on first row of QTableview while data displaying.While selecting first row, data will displays in line edit boxes.
I am not able to foucus on the first row selection. QSqlQueryModel i am using
If I manually clicked then its working,means first row data displaying in Line edit boxes.please suggest.

my code below

ui->TbleViewUserMgmt->setSelectionMode(QAbstractItemView::SingleSelectio n);
ui->TbleViewUserMgmt->selectRow(0);
ui->TbleViewUserMgmt->setFocus();

adutzu89
16th May 2014, 16:36
Try:

ui->TbleViewUserMgmt->setSelectionMode(QAbstractItemView::SingleSelectio n);
ui->TbleViewUserMgmt->setFocus();
ui->TbleViewUserMgmt->selectRow(0);

Set focus after you set the model.