PDA

View Full Version : How to know which qtableview is currently displayed



pcheng
12th June 2012, 10:48
Hello everyone. I am just another newbie trying to develop some code on QT. Up until now I have been able to find most of the answers to my questions online but now I have a question that needs your expert advice.

I have a window that connects to a database and displays the contents in Qtableview. The twist here is that based on the value of a field the records are filtered into 5 different tableviews each in its own tabbed page. A view of the window is shown below.

7854

Now I have 1 problem and 1 concern.

The problem is that the edit button only works for the first tableview because I have it hardcoded in the Find code as shown.
int pIndex = ui->tableView->model()->index(ui->tableView->currentIndex().row(),0).data().toInt();

How can I make the code understand that I moved to a new tableview and the edit button will get the index of that view?

The concern that I have is that for each tableview I create a new model and filter the model based on each value of the field I want. Namely the weight as shown in the image. Is that the right way of doing it or am I complicating stuff?

Thanking you in advance for all your help,

Pericles

Lesiok
12th June 2012, 12:01
You are using QTabWidget. So use QTabWidget::currentIndex method to detect selected tab.

pcheng
15th June 2012, 09:55
Thank you for your prompt reply. This was exactly what I was looking for.

Pericles