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] How to disable the Next button in a wizard until a certain condition is met
Forum Updated to NodeBB v4.3 + New Features

[QWizard] How to disable the Next button in a wizard until a certain condition is met

Scheduled Pinned Locked Moved General and Desktop
15 Posts 4 Posters 11.1k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 11 Sept 2013, 09:51 last edited by
    #3

    Hi and welcome to devnet,

    You might be interested by re-implementing "QWizardPage::isComplete":http://qt-project.org/doc/qt-4.8/qwizardpage.html#isComplete

    Hope it helps

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 11 Sept 2013, 09:52 last edited by
      #4

      Or subclass QWizardPage and reimplement isCompleted.

      (Z(:^

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pkjag
        wrote on 11 Sept 2013, 10:06 last edited by
        #5

        Thank you all for replying.
        So i did this:

        @
        connect(checkmeCheckBox, SIGNAL(stateChanged(), QWizard::NextButton, SLOT(nextId())));
        ...
        ...
        ...
        //for all the checkboxes

        int myclass::nextId()
        {
        //then i got stuck here since you can't evaluate the logic for all the four checkboxes since there are like a total of 10 of them and i want to select any four from the 10??
        }
        @

        1 Reply Last reply
        0
        • P Offline
          P Offline
          pkjag
          wrote on 11 Sept 2013, 15:14 last edited by
          #6

          Hey
          Is there no actual help in this forum, where did everyone go??
          I've been waiting for like 4 hours!!!! ):

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 11 Sept 2013, 18:40 last edited by
            #7

            Please, wait at least 24 to 72 hours before bumping your own thread. Most people answering here do it on their free time. Also not everybody lives in the same timezone as you.

            If you're in need of rapid support you can contact Digia/KDAB/ICS etc...

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sierdzio
              Moderators
              wrote on 12 Sept 2013, 04:09 last edited by
              #8

              Mate, there is no magic automated solution here. This is custom behaviour and you need to sit down, think about it and implement the code.

              Regardless of how many checkboxes you have, be it 10 or a hundred, you need to go through them all and count how many are checked.

              (Z(:^

              1 Reply Last reply
              0
              • P Offline
                P Offline
                p3c0
                Moderators
                wrote on 12 Sept 2013, 06:56 last edited by
                #9

                pkjag,
                Once you subclass QWizardPage, you will get access to the "Next" button using the wizard()->button(QWizard::NextButton). When you check any checkbox, call a common slot and check there the status of all the checkboxes and depending upon your condition call set the "Next" button state using @wizard()->button(QWizard::NextButton)->setEnabled(true)@ or @wizard()->button(QWizard::NextButton)->setEnabled(false)@

                157

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  pkjag
                  wrote on 12 Sept 2013, 11:41 last edited by
                  #10

                  So i did this:
                  @
                  connect(checkmeCheckBox, SIGNAL(toggled()),wizard1->button(QWizard::NextButton), SLOT(reactToToggle()));
                  ...
                  ...
                  ...
                  //for all the checkboxes in myPage

                  int myPage::reactToToggle(bool checked)
                  {
                  static int i = 0;
                  if(checked)
                  ++i;
                  return i;
                  }

                  void myPage::returns(bool checked)
                  {
                  if(reactToToggle(checked)== 3)
                  wizard1->button(QWizard::NextButton)->setEnabled(true);
                  else
                  wizard1->button(QWizard::NextButton)->setDisabled(true);
                  }
                  @
                  but the compiler returns a SIGSEGV error, is there anything wrong with my implementation apart from the SIGSEGV exception???

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    p3c0
                    Moderators
                    wrote on 12 Sept 2013, 12:22 last edited by
                    #11

                    Hi,

                    Please check the following code:
                    Check the SLOT CheckAllCheckBoxes(bool)

                    installer.cpp

                    @#include "installer.h"

                    Installer::Installer(QWidget *parent)
                    : QWizard(parent)
                    {
                    setPage(Page_Intro, new IntroPage);
                    setPage(Page_Register, new RegisterPage);
                    setStartId(Page_Intro);
                    setWindowTitle(tr("Test Wizard"));

                    }

                    Installer::~Installer()
                    {

                    }

                    IntroPage::IntroPage(QWidget *parent)
                    : QWizardPage(parent)
                    {
                    setTitle(tr("Introduction"));
                    }

                    void IntroPage::initializePage()
                    {
                    topLabel = new QLabel(tr("Test Wizard. \n Please click next to install"));
                    topLabel->setWordWrap(true);

                    m_one = new QCheckBox();m_one->setText("one");
                    connect(m_one,SIGNAL(clicked(bool)),this,SLOT(CheckAllCheckBoxes(bool)));
                    m_two = new QCheckBox();m_two->setText("two");
                    connect(m_two,SIGNAL(clicked(bool)),this,SLOT(CheckAllCheckBoxes(bool)));
                    m_three = new QCheckBox();m_three->setText("three");
                    connect(m_three,SIGNAL(clicked(bool)),this,SLOT(CheckAllCheckBoxes(bool)));
                    m_four = new QCheckBox();m_four->setText("four");
                    connect(m_four,SIGNAL(clicked(bool)),this,SLOT(CheckAllCheckBoxes(bool)));
                    
                    QVBoxLayout *layout = new QVBoxLayout;
                    layout->addWidget(topLabel);
                    
                    layout->addWidget(m_one);
                    layout->addWidget(m_two);
                    layout->addWidget(m_three);
                    layout->addWidget(m_four);
                    setLayout(layout);
                    

                    }

                    bool IntroPage::validatePage()
                    {
                    return Installer::Page_Register;
                    }

                    void IntroPage::CheckAllCheckBoxes(bool state)
                    {
                    int checkcount = 0;

                    QList<QCheckBox *> allcheckboxes = findChildren<QCheckBox *>();
                    for(int i=0;i<allcheckboxes.count();i++)
                    {
                        if(allcheckboxes.at(i)->isChecked())
                            checkcount++;
                    }
                    if(checkcount>2)
                        wizard()->button(QWizard::NextButton)->setEnabled(true);
                    else
                        wizard()->button(QWizard::NextButton)->setEnabled(false);
                    

                    }

                    //--------------------------

                    RegisterPage::RegisterPage(QWidget *parent)
                    : QWizardPage(parent)
                    {
                    setTitle(tr("Test Wizard Page 2"));
                    setSubTitle(tr("Please wait..."));

                    }

                    void RegisterPage::initializePage()
                    {
                    line = new QLineEdit;
                    line->setHidden(true);

                    QVBoxLayout *layout = new QVBoxLayout;
                    layout->addWidget(bar,1,0);
                    layout->addWidget(line,2,0);
                    setLayout(layout);
                    

                    }

                    bool RegisterPage::validatePage()
                    {
                    }

                    int RegisterPage::EnableNextFinish()
                    {
                    line->setText("157");
                    setSubTitle("Completed");
                    }

                    bool RegisterPage::isComplete()
                    {
                    return true;
                    }
                    @

                    installer.h

                    @#ifndef INSTALLER_H
                    #define INSTALLER_H

                    #include <QtGui>

                    class Installer : public QWizard
                    {
                    Q_OBJECT

                    public:
                    Installer(QWidget *parent = 0);
                    enum { Page_Intro,Page_Register};
                    ~Installer();
                    };

                    class IntroPage : public QWizardPage
                    {
                    Q_OBJECT

                    public:
                    IntroPage(QWidget *parent = 0);
                    bool validatePage();

                    void initializePage();
                    

                    private:
                    QLabel *topLabel;
                    QCheckBox *m_one,*m_two,*m_three,*m_four;
                    QRadioButton *registerRadioButton;
                    QRadioButton *evaluateRadioButton;

                    protected slots:
                    void CheckAllCheckBoxes(bool state);
                    };

                    class RegisterPage : public QWizardPage
                    {
                    Q_OBJECT

                    public:
                    RegisterPage(QWidget *parent = 0);
                    void initializePage();
                    QLineEdit *line;
                    bool validatePage();

                    private:
                    public slots:
                    int EnableNextFinish();
                    bool isComplete();
                    };
                    #endif // INSTALLER_H
                    @

                    157

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      pkjag
                      wrote on 12 Sept 2013, 17:15 last edited by
                      #12

                      Thanks p3c0
                      It worked save for the fact that the Next button is enabled before you actually click the checkboxes and it allows going forward to the next page.
                      I don't know where to call the disabling function since i tried it in the constructor and it didn't work??

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        p3c0
                        Moderators
                        wrote on 13 Sept 2013, 04:54 last edited by
                        #13

                        Right. Doesn't even work in initializePage(). Just wondering why it didn't work

                        157

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          p3c0
                          Moderators
                          wrote on 13 Sept 2013, 05:05 last edited by
                          #14

                          It works in showEvent().

                          Try adding this function to the above code

                          @void IntroPage::showEvent(QShowEvent *)
                          {
                          wizard()->button(QWizard::NextButton)->setEnabled(false);
                          }@

                          157

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            pkjag
                            wrote on 13 Sept 2013, 06:36 last edited by
                            #15

                            Thanks man it worked

                            1 Reply Last reply
                            0

                            12/15

                            12 Sept 2013, 17:15

                            • Login

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