Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTabWidget pages OnSetActive()?



  • I'm converting some MFC code that uses tabbed dialogs implemented using CPropertySheet and CPropertyPage.

    This code makes use of the CPropertyPage::OnSetActive() method which is invoked when the individual tab is made the active tab This code can't be placed in the ctor in most cases as it depends on the actual conditions at the time the tab is activated.

    I've been digging through the documentation to try to find the equivalent of this in Qt, but so far haven't come up with anything.

    Please could someone take pity on a Qt beginner and point me to the relevant docs/samples.

    Thanks
    David



  • I don't know about this method.
    But from you description, I feel it similar to the signal of QTabWidget

    void  currentChanged(int index)
    

    If it is not, can you describe more about how do you need to use it?



  • Thanks Bonnie I'll take a look at that. Further digging suggests that this:

    void MyDialogue::showEvent(QShowEvent *event)
    {
    	if (!event->spontaneous())
            {
                // Do stuff here
            }
    
           // Invoke base class showEvent()
          return QDialog::showEvent(event);
    }
    

    might also be relevant.

    David



  • @Perdrix
    Depending on how it's supposed to work, @Bonnie's currentChanged() may be what you need. But I found I needed to use QApplication::focusChanged() --- or you could use individual page's "focus" event if you are sub-classing --- to get correct signal for some purposes, You may need to look at both. I'm not sure.



  • @Bonnie said in QTabWidget pages OnSetActive()?:

    I don't know about this method.
    But from you description, I feel it similar to the signal of QTabWidget

    void  currentChanged(int index)
    

    If it is not, can you describe more about how do you need to use it?

    That might work but seems a little roundabout requiring each individual sub-dialogue to have a slot for that signal and then work out if it applies to them?

    D.



  • @Perdrix I googled OnSetActive, seems that it should be implemented in every tab page?
    So you mean if you use currentChanged, you will need to create a slot for every page and connect the signal to them?
    I don't think this is a good way. Maybe you can look at @JonB 's focus event stuff.

    I also have another thought, a bit complicated.
    You can define a public slot named OnSetActive in every page.
    And you connect currentChanged to a slot in which you get the current page and invoke its OnSetActive slot by

    if(QWidget* widget = tabWidget->currentWidget())
        QMetaObject::invokeMethod(widget, "OnSetActive");
    


  • @Bonnie said in QTabWidget pages OnSetActive()?:

    QMetaObject::invokeMethod(widget, "OnSetActive");

    Ooh! Sneaky - I much prefer that to handling Show Events.

    So long as the currentChanged(int tab) signal is emitted for the first tab that is auto-selected ...

    I'll give it a try! Though it will be some days before I can run the code (huge editing task in hand).


Log in to reply