Results 1 to 3 of 3

Thread: Act when QTableView::isVisible()

  1. #1
    Join Date
    Aug 2013
    Posts
    32
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Act when QTableView::isVisible()

    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.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Act when QTableView::isVisible()

    Don't depend on isVisbile(), instead implement QTreeView::showEvent(), and emit a signal from there and in a connected slot enable/disable the required widgets.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. The following user says thank you to Santosh Reddy for this useful post:

    i92guboj (28th November 2013)

  4. #3
    Join Date
    Aug 2013
    Posts
    32
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Act when QTableView::isVisible()

    I got it. It worked without a problem, in combination with the reimplementation of ::hideEvent() as well.

    Thank you.

Similar Threads

  1. QTableView and QLineEdit OUTSIDE of QTableView, like Excel
    By JoZCaVaLLo in forum Qt Programming
    Replies: 10
    Last Post: 13th May 2011, 13:20
  2. Replies: 5
    Last Post: 5th December 2010, 17:23
  3. Can't see widget, yet isVisible() returns true
    By MattPhillips in forum Qt Programming
    Replies: 1
    Last Post: 5th December 2010, 12:56
  4. Replies: 2
    Last Post: 26th November 2009, 04:45
  5. problem with QFrame isVisible()
    By impeteperry in forum Qt Programming
    Replies: 1
    Last Post: 5th August 2008, 16:29

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.