Search code examples
qttabindexqmessagebox

QMessageBox and tabOrdering


Is there any way to setTabOrder in QMessageBox without subclassing it or writing my own? In cases when you already got big project - this might be useful.


Solution

  • Is there any way to setTabOrder in QMessageBox without subclassing it or writing my own? In cases when you already got big project - this might be useful.

    There is a way to use setTabOrder in QMessageBox. All you need is QWidget* pointers to 'from' and 'to' tabs.

    class MyApp
    {
       // ...
       void tabOrdering();
       QMessagebox* m_pMsgBox; 
    }
    
    void MyApp::tabOrdering()
    {
         auto* pSaveBn = m_pMsgBox->addButton(QMessagebox::Save);
         m_pMsgBox->setTabOrder(m_pMsgBox->defaultButton(), pSaveBn);
    }
    

    You may also consider using QObject::findChild method for finding tab widget stops.