Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-2470

[QStackedWidget] When using a stacked widget in a QWidget and pressing tab focus is not set correctly.

    XMLWordPrintable

Details

    Description

      When using a stacked widget in a QWidget and pressing tab focus is not set correctly.
      I.E. if you have a QDialog containing several widgets, including a QStackedWidget and these are ordered in a layout; no matter where the stacked widget is placed all the other widgets will get focus before the stacked widgets children when tab is pressed.

      If you have a button, a stacked widget and another button in a vertical layout, and also say that the stacked widget contains a QComboBox. If the top button has focus, and then tab is pressed, the focus will go to the bottom button before the combo box get focus. This is despite the fact that the combo box is placed in the middle of the window.

      • How to reproduce:
        1. Build and compile the code.
        2. Start the application and press the tab key several times.
      • Expected result:
        Focus set in this order:
        1. Top button
        2. Combo box
        3. Bottom button
      • Actual result:
        Focus set in this order:
        1. Top button
        2. Bottom button
        3. Combo box

      Test case main.cpp to reproduce issue using details above
      ============================================

      #include <QtGui>
      class ConfigurationPage : public QWidget{
      public:
          ConfigurationPage(QWidget *parent = 0);
      };
      
      ConfigurationPage::ConfigurationPage(QWidget *parent): QWidget(parent){
          QLabel *serverLabel = new QLabel(tr("Server:"),this);
          QComboBox *serverCombo = new QComboBox(this);
          serverCombo->addItem(tr("Trolltech (Australia)"));
          serverCombo->addItem(tr("Trolltech (Germany)"));
      
          QHBoxLayout *serverLayout = new QHBoxLayout;
          serverLayout->addWidget(serverLabel);
          serverLayout->addWidget(serverCombo);
      
          setLayout(serverLayout);
      }
      
      class ConfigDialog : public QDialog{
          Q_OBJECT
      public:
          ConfigDialog();
       QWidget *myWidget;
       QStackedWidget *stackedWidget;
      };
      
      ConfigDialog::ConfigDialog(){
       QPushButton *button = new QPushButton("test");
       QPushButton *button2 = new QPushButton("test");
       QPushButton *button3 = new QPushButton("test");
       ConfigurationPage *p = new ConfigurationPage();
       stackedWidget = new QStackedWidget(this);
       stackedWidget->addWidget(p);
       stackedWidget->setCurrentWidget( p );
      
       QVBoxLayout *layout = new QVBoxLayout;
       layout->addWidget(button);
       layout->addWidget(button2);
       layout->addWidget(stackedWidget);
       layout->addWidget(button3);
       setLayout(layout);
      }
      int main(int argc, char *argv[]){
           QApplication app(argc, argv);
           ConfigDialog mainWid;
           mainWid.show();
           return app.exec();
       }
      #include "main.moc"
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            engvolds Morten Engvoldsen (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes