Hello.

I am using the isVisible() property to select the currently displayed QTableView, amongst a total of four.

That adjusts a pointer so that I can move a widget across the many tabs where the QTableView live. Right. The problem is that, depending on many factors, the QTableView in a given tabs can be shown or hidden, and, in turn, the widget needs to be enabled or disabled. The code is like this:

Qt Code:
  1. void kooker::setCurrentTableView()
  2. {
  3. // first, we move the listEditWidget to the new current tab
  4.  
  5. QTabWidget *tab = static_cast<QTabWidget*>(ui->tabs->widget(ui->tabs->currentIndex()));
  6. QGridLayout *layout = static_cast<QGridLayout*>(tab->layout());
  7. if((ui->tabs->count() - 1) != ui->tabs->currentIndex())
  8. {
  9. layout->addWidget(ui->listEditWidget, 0, 0);
  10. }
  11.  
  12. // get the visible table
  13.  
  14. currentTableView = getVisibleTable();
  15.  
  16. // if there's one, we enable the widget, else we disable it
  17.  
  18. if(!currentTableView)
  19. {
  20. ui->listEditWidget->setEnabled(false);
  21. }
  22. else
  23. {
  24. ui->listEditWidget->setEnabled(true);
  25. connect(currentTableView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
  26. this, SLOT(checkAddNoteButton()));
  27. }
  28. }
  29.  
  30. QTableView *kooker::getVisibleTable()
  31. {
  32. if(ui->tableView_cascosYAccesorios->isVisible())
  33. {
  34. return ui->tableView_cascosYAccesorios;
  35. }
  36. else if(ui->tableView_Elec->isVisible())
  37. {
  38. return ui->tableView_Elec;
  39. }
  40. else if(ui->tableView_PuertasYCajones->isVisible())
  41. {
  42. return ui->tableView_PuertasYCajones;
  43. }
  44. else if(ui->tv_herrajes->isVisible())
  45. {
  46. return ui->tv_herrajes;
  47. }
  48. else if(ui->tv_varios->isVisible())
  49. {
  50. return ui->tv_varios;
  51. }
  52. else
  53. {
  54. return NULL;
  55. }
  56. }
To copy to clipboard, switch view to plain text mode 

Not 100% elegant, but it works (mostly, anyway). In the constructor I have:

Qt Code:
  1. connect(ui->tabs, SIGNAL(currentChanged(int)), this, SLOT(setCurrentTableView()));
To copy to clipboard, switch view to plain text mode 

Which does all the magic when I change he current tab. But, what happens when the program starts? No currentChanged() seems to be automatically emitted when displaying the tabs widget, so, I have to run setCurrentTableView() in the constructor. But that doesn't seem to work either, because currentTableView, according to the debugger, points to 0x0, and, hence, the listEditWidget is not enabled and remains greyed.

So, can you think of any way to either:
  1. wait for ui->tableView*'s to be rendered so that isVisible() on them returns 'TRUE', or
  2. do this in a more elegant way


Thanks for any idea you can share, or just for reading.