Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWizard : clear focus Next Button

QWizard : clear focus Next Button

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 2 Posters 5.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #2

    hmmmm.
    Maybe you can set focus to something else in code?
    But why you want to do it?

    validatePage() can be used to control if user can press next.
    Or QWizardPage::isComplete() to disable it.

    F 1 Reply Last reply
    0
    • mrjjM mrjj

      hmmmm.
      Maybe you can set focus to something else in code?
      But why you want to do it?

      validatePage() can be used to control if user can press next.
      Or QWizardPage::isComplete() to disable it.

      F Offline
      F Offline
      fgdevel
      wrote on last edited by
      #3

      @mrjj

      how to set validatePage() to false ?

      mrjjM 1 Reply Last reply
      0
      • F fgdevel

        @mrjj

        how to set validatePage() to false ?

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @fgdevel

        It is a virtual function so you must create your own page child class to set it.
        and then use MyPage in the wizard.
        Something like

        #include <QWizard>
        #include <QWizardPage>
        
        class MyPage : public QWizardPage{
        public:
          MyPage(QWidget* parent=0):QWizardPage(parent){  }
          virtual bool validatePage()(){return false;}
        };
        
        F 1 Reply Last reply
        0
        • mrjjM mrjj

          @fgdevel

          It is a virtual function so you must create your own page child class to set it.
          and then use MyPage in the wizard.
          Something like

          #include <QWizard>
          #include <QWizardPage>
          
          class MyPage : public QWizardPage{
          public:
            MyPage(QWidget* parent=0):QWizardPage(parent){  }
            virtual bool validatePage()(){return false;}
          };
          
          F Offline
          F Offline
          fgdevel
          wrote on last edited by
          #5

          @mrjj

          with your code, when I call validatePage(), the Next Button is already focused...

          mrjjM 1 Reply Last reply
          0
          • F fgdevel

            @mrjj

            with your code, when I call validatePage(), the Next Button is already focused...

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @mrjj said:

            validatePage

            This virtual function is called by QWizard::validateCurrentPage() when the user clicks Next or Finish to perform some last-minute validation. If it returns true, the next page is shown (or the wizard finishes); otherwise, the current page stays up.

            So I assumed that is what you wanted?

            F 1 Reply Last reply
            0
            • mrjjM mrjj

              @mrjj said:

              validatePage

              This virtual function is called by QWizard::validateCurrentPage() when the user clicks Next or Finish to perform some last-minute validation. If it returns true, the next page is shown (or the wizard finishes); otherwise, the current page stays up.

              So I assumed that is what you wanted?

              F Offline
              F Offline
              fgdevel
              wrote on last edited by
              #7

              @mrjj

              not at all.
              I want to see the QWizard page but with the focus disabled on the Next button

              mrjjM 1 Reply Last reply
              0
              • F fgdevel

                @mrjj

                not at all.
                I want to see the QWizard page but with the focus disabled on the Next button

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @fgdevel
                Ok it means user can still just click on it ?

                You can just set focus to something then using
                setFocus();
                Like one of your own buttons or a textedit.

                F 1 Reply Last reply
                0
                • mrjjM mrjj

                  @fgdevel
                  Ok it means user can still just click on it ?

                  You can just set focus to something then using
                  setFocus();
                  Like one of your own buttons or a textedit.

                  F Offline
                  F Offline
                  fgdevel
                  wrote on last edited by
                  #9

                  @mrjj

                  Yes, it's just the focus I want to remove.
                  Because I use i QWizard page, it's not simple

                  mrjjM 1 Reply Last reply
                  0
                  • F fgdevel

                    @mrjj

                    Yes, it's just the focus I want to remove.
                    Because I use i QWizard page, it's not simple

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @fgdevel
                    By remove focus you mean so that if user hit say enter, then nothing happens?
                    Or what is thee goal of what you want?

                    F 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @fgdevel
                      By remove focus you mean so that if user hit say enter, then nothing happens?
                      Or what is thee goal of what you want?

                      F Offline
                      F Offline
                      fgdevel
                      wrote on last edited by
                      #11

                      @mrjj

                      yes it's the goal. When the user press Enter key, nothing happens

                      mrjjM 1 Reply Last reply
                      0
                      • F fgdevel

                        @mrjj

                        yes it's the goal. When the user press Enter key, nothing happens

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by mrjj
                        #12

                        @fgdevel
                        but that is 100% what validatePage does.
                        If you return false, the Next dont work/nothing happens.
                        Dont matter if you hit enter or click on it.

                        So that is why im confused of what you really mean.

                        F 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @fgdevel
                          but that is 100% what validatePage does.
                          If you return false, the Next dont work/nothing happens.
                          Dont matter if you hit enter or click on it.

                          So that is why im confused of what you really mean.

                          F Offline
                          F Offline
                          fgdevel
                          wrote on last edited by
                          #13

                          @mrjj

                          I want Next button works. But just focus not

                          mrjjM 1 Reply Last reply
                          0
                          • F fgdevel

                            @mrjj

                            I want Next button works. But just focus not

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #14

                            @fgdevel
                            ok so you want user to click on it.

                            Have a look at setFocusProxy();

                            http://ldc.usb.ve/docs/qt/dialogs-complexwizard.html

                            It seems that you can call that in a Pages constructor and then it will give focus to that widget when page is
                            shown.

                            F 1 Reply Last reply
                            0
                            • mrjjM mrjj

                              @fgdevel
                              ok so you want user to click on it.

                              Have a look at setFocusProxy();

                              http://ldc.usb.ve/docs/qt/dialogs-complexwizard.html

                              It seems that you can call that in a Pages constructor and then it will give focus to that widget when page is
                              shown.

                              F Offline
                              F Offline
                              fgdevel
                              wrote on last edited by
                              #15

                              @mrjj

                              I have used diffrent setFocus functions but none of them seems to work...

                              mrjjM 1 Reply Last reply
                              0
                              • F fgdevel

                                @mrjj

                                I have used diffrent setFocus functions but none of them seems to work...

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #16

                                @fgdevel
                                Hi
                                You are right. by magic it can still hit enter on Next...

                                I changed sample "trivialwizard" to use eventfilter.
                                That can eat the enter key. :)
                                so key changes are
                                class myEventFilter: public QObject // the event filer
                                app.installEventFilter(new myEventFilter()); // using the filter

                                #include <QtWidgets>
                                #include <QTranslator>
                                #include <QLocale>
                                #include <QLibraryInfo>
                                QWizard* wizardp;
                                QWizardPage* createIntroPage() {
                                  QWizardPage* page = new QWizardPage;
                                  page->setTitle("Introduction");
                                
                                  QLabel* label = new QLabel("This wizard will help you register your copy "
                                                             "of Super Product Two.");
                                  label->setWordWrap(true);
                                  QLineEdit* nameLineEdit = new QLineEdit;
                                
                                  QVBoxLayout* layout = new QVBoxLayout;
                                  layout->addWidget(label);
                                  layout->addWidget(nameLineEdit);
                                  page->setLayout(layout);
                                
                                
                                  wizardp->button(QWizard::CancelButton)-> setFocus();
                                  return page;
                                }
                                
                                QWizardPage* createRegistrationPage()
                                {
                                  //! [3]
                                  QWizardPage* page = new QWizardPage;
                                  page->setTitle("Registration");
                                  page->setSubTitle("Please fill both fields.");
                                
                                  QLabel* nameLabel = new QLabel("Name:");
                                  QLineEdit* nameLineEdit = new QLineEdit;
                                
                                  QLabel* emailLabel = new QLabel("Email address:");
                                  QLineEdit* emailLineEdit = new QLineEdit;
                                
                                  QGridLayout* layout = new QGridLayout;
                                  layout->addWidget(nameLabel, 0, 0);
                                  layout->addWidget(nameLineEdit, 0, 1);
                                  layout->addWidget(emailLabel, 1, 0);
                                  layout->addWidget(emailLineEdit, 1, 1);
                                  page->setLayout(layout);
                                
                                  return page;
                                  //! [4]
                                }
                                //! [2] //! [4]
                                
                                //! [5] //! [6]
                                QWizardPage* createConclusionPage()
                                //! [5] //! [7]
                                {
                                  //! [7]
                                  QWizardPage* page = new QWizardPage;
                                  page->setTitle("Conclusion");
                                
                                  QLabel* label = new QLabel("You are now successfully registered. Have a "
                                                             "nice day!");
                                  label->setWordWrap(true);
                                
                                  QVBoxLayout* layout = new QVBoxLayout;
                                  layout->addWidget(label);
                                  page->setLayout(layout);
                                
                                  return page;
                                  //! [8]
                                }
                                //! [6] //! [8]
                                // this you need
                                class myEventFilter: public QObject {
                                 public:
                                  myEventFilter(): QObject() {}
                                  ~myEventFilter() {}
                                  bool eventFilter(QObject* object, QEvent* event) {
                                    if (event->type() == QEvent::KeyPress) {
                                      QKeyEvent* key = static_cast<QKeyEvent*>(event);
                                      if ( (key->key() == Qt::Key_Enter) || (key->key() == Qt::Key_Return) ) {
                                        event->ignore();
                                      } else {
                                        return QObject::eventFilter(object, event);
                                      }
                                    }
                                  }
                                };
                                
                                //! [9] //! [10]
                                int main(int argc, char* argv[])
                                //! [9] //! [11]
                                {
                                  QApplication app(argc, argv);
                                
                                #ifndef QT_NO_TRANSLATION
                                  QString translatorFileName = QLatin1String("qt_");
                                  translatorFileName += QLocale::system().name();
                                  QTranslator* translator = new QTranslator(&app);
                                  if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
                                    app.installTranslator(translator);
                                #endif
                                
                                  QWizard wizard;
                                  wizardp = &wizard;
                                  wizard.addPage(createIntroPage());
                                  wizard.addPage(createRegistrationPage());
                                  wizard.addPage(createConclusionPage());
                                
                                  wizard.setWindowTitle("Trivial Wizard");
                                  wizard.show();
                                  app.installEventFilter(new myEventFilter()); // install filter
                                  return app.exec();
                                }
                                //! [10] //! [11]
                                
                                F 1 Reply Last reply
                                0
                                • mrjjM mrjj

                                  @fgdevel
                                  Hi
                                  You are right. by magic it can still hit enter on Next...

                                  I changed sample "trivialwizard" to use eventfilter.
                                  That can eat the enter key. :)
                                  so key changes are
                                  class myEventFilter: public QObject // the event filer
                                  app.installEventFilter(new myEventFilter()); // using the filter

                                  #include <QtWidgets>
                                  #include <QTranslator>
                                  #include <QLocale>
                                  #include <QLibraryInfo>
                                  QWizard* wizardp;
                                  QWizardPage* createIntroPage() {
                                    QWizardPage* page = new QWizardPage;
                                    page->setTitle("Introduction");
                                  
                                    QLabel* label = new QLabel("This wizard will help you register your copy "
                                                               "of Super Product Two.");
                                    label->setWordWrap(true);
                                    QLineEdit* nameLineEdit = new QLineEdit;
                                  
                                    QVBoxLayout* layout = new QVBoxLayout;
                                    layout->addWidget(label);
                                    layout->addWidget(nameLineEdit);
                                    page->setLayout(layout);
                                  
                                  
                                    wizardp->button(QWizard::CancelButton)-> setFocus();
                                    return page;
                                  }
                                  
                                  QWizardPage* createRegistrationPage()
                                  {
                                    //! [3]
                                    QWizardPage* page = new QWizardPage;
                                    page->setTitle("Registration");
                                    page->setSubTitle("Please fill both fields.");
                                  
                                    QLabel* nameLabel = new QLabel("Name:");
                                    QLineEdit* nameLineEdit = new QLineEdit;
                                  
                                    QLabel* emailLabel = new QLabel("Email address:");
                                    QLineEdit* emailLineEdit = new QLineEdit;
                                  
                                    QGridLayout* layout = new QGridLayout;
                                    layout->addWidget(nameLabel, 0, 0);
                                    layout->addWidget(nameLineEdit, 0, 1);
                                    layout->addWidget(emailLabel, 1, 0);
                                    layout->addWidget(emailLineEdit, 1, 1);
                                    page->setLayout(layout);
                                  
                                    return page;
                                    //! [4]
                                  }
                                  //! [2] //! [4]
                                  
                                  //! [5] //! [6]
                                  QWizardPage* createConclusionPage()
                                  //! [5] //! [7]
                                  {
                                    //! [7]
                                    QWizardPage* page = new QWizardPage;
                                    page->setTitle("Conclusion");
                                  
                                    QLabel* label = new QLabel("You are now successfully registered. Have a "
                                                               "nice day!");
                                    label->setWordWrap(true);
                                  
                                    QVBoxLayout* layout = new QVBoxLayout;
                                    layout->addWidget(label);
                                    page->setLayout(layout);
                                  
                                    return page;
                                    //! [8]
                                  }
                                  //! [6] //! [8]
                                  // this you need
                                  class myEventFilter: public QObject {
                                   public:
                                    myEventFilter(): QObject() {}
                                    ~myEventFilter() {}
                                    bool eventFilter(QObject* object, QEvent* event) {
                                      if (event->type() == QEvent::KeyPress) {
                                        QKeyEvent* key = static_cast<QKeyEvent*>(event);
                                        if ( (key->key() == Qt::Key_Enter) || (key->key() == Qt::Key_Return) ) {
                                          event->ignore();
                                        } else {
                                          return QObject::eventFilter(object, event);
                                        }
                                      }
                                    }
                                  };
                                  
                                  //! [9] //! [10]
                                  int main(int argc, char* argv[])
                                  //! [9] //! [11]
                                  {
                                    QApplication app(argc, argv);
                                  
                                  #ifndef QT_NO_TRANSLATION
                                    QString translatorFileName = QLatin1String("qt_");
                                    translatorFileName += QLocale::system().name();
                                    QTranslator* translator = new QTranslator(&app);
                                    if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
                                      app.installTranslator(translator);
                                  #endif
                                  
                                    QWizard wizard;
                                    wizardp = &wizard;
                                    wizard.addPage(createIntroPage());
                                    wizard.addPage(createRegistrationPage());
                                    wizard.addPage(createConclusionPage());
                                  
                                    wizard.setWindowTitle("Trivial Wizard");
                                    wizard.show();
                                    app.installEventFilter(new myEventFilter()); // install filter
                                    return app.exec();
                                  }
                                  //! [10] //! [11]
                                  
                                  F Offline
                                  F Offline
                                  fgdevel
                                  wrote on last edited by
                                  #17

                                  @mrjj

                                  I've found a solution with :

                                  this->setOptions(QWizard::NoDefaultButton);
                                  this->setOption(QWizard::NoDefaultButton, true);

                                  mrjjM 1 Reply Last reply
                                  1
                                  • F fgdevel

                                    @mrjj

                                    I've found a solution with :

                                    this->setOptions(QWizard::NoDefaultButton);
                                    this->setOption(QWizard::NoDefaultButton, true);

                                    mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by mrjj
                                    #18

                                    @fgdevel
                                    super.
                                    Thank you for reporting back.

                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved