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. How to properly handle user input with multiple fields

How to properly handle user input with multiple fields

Scheduled Pinned Locked Moved General and Desktop
15 Posts 6 Posters 17.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.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #3

    What you need is some kind of dialog to get your user interaction.

    I did not chance upon QInputPanel in the Qt documentation, but perhaps you are looking for QInputDialog? That class is not suited for what you want, because it only supports a single input value. Instead you should create your own dialog from scratch. Easiest is to use Qt Creator. Simply choose File -> New file or project, Select "Qt" under "Files and Classes" on the left, and choose Qt Designer Form Class in the top right. Follow the wizard (use some sensible names for your class please), and use the Designer to design your dialog.

    On the validation side of things: study QValidator. It is probably sufficient for your needs. Just enable or disable the OK button on your form depending on if all three inputs validate properly.

    This should get you started, I think.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mchris357
      wrote on last edited by
      #4

      Thanks! This worked. I had far more than I actually needed to get this thing running. One quick question for you though...my buttons are setup in a default button box like this:

      @buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok );@

      How to I go about disabling (greying out) the Ok button in this context? I would assume I need to get a handle for QDialogButtonBox::Ok, but it's only a parameter and not an object itself. How do I get to the object representing the Ok button?

      Thanks! You've already been a major help!

      On a side note, is there any reference book you would highly recommend I have in my arsenal for Qt programming?
      Thanks!

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #5

        Afaik, it works like this:

        @
        buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
        @

        EDIT: fixed a code bug :-) Gerolf

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mchris357
          wrote on last edited by
          #6

          I tried putting that immediately after the definition of the buttonbox (see below), and it doesn't kick up an error (which is always pleasant). When I ran the program, though, the Ok button was still clickable. Does this need to be communicated to the form in another way?

          What do I need to put around the code to make it...errr...readable? :)

          Thanks!

          @
          void setupUi(QDialog *Dialog)
          {
          if (Dialog->objectName().isEmpty())
          Dialog->setObjectName(QString::fromUtf8("Dialog"));
          Dialog->setEnabled(true);
          Dialog->resize(400, 300);
          buttonBox = new QDialogButtonBox(Dialog);
          buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
          buttonBox->setGeometry(QRect(50, 250, 341, 32));
          buttonBox->setOrientation(Qt::Horizontal);
          buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok );

              //Test code
              buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
          

          @

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            ZapB
            wrote on last edited by
            #7

            You can use "@" symbols to delimit blocks of code in your posts or click on the "Code" button in the editor toolbar (the rightmost one).

            Nokia Certified Qt Specialist
            Interested in hearing about Qt related work

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              ZapB
              wrote on last edited by
              #8

              You're not editing the auto-generated ui code are you by any chance?

              Nokia Certified Qt Specialist
              Interested in hearing about Qt related work

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mchris357
                wrote on last edited by
                #9

                Yes, I am. Where do I need to be putting this?

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  giesbert
                  wrote on last edited by
                  #10

                  I'm not sure whether there was an issue with this. Try out doing this in the show() - event of the dialok. I think there was something...

                  Nokia Certified Qt Specialist.
                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mchris357
                    wrote on last edited by
                    #11

                    I don't quite get what you're saying. I'm currently using this to invoke the dialog (slot triggered by a signal from a clicked main menu item):

                    @
                    void VCMainWindow::InvokeMPDDialogWindow()

                    { /BEGIN FUNCTION INVOKEMPDDIALOGWINDOW/

                    VCMPDataInputForm NewForm;

                    NewForm.setWindowTitle( "New Dataset");

                    NewForm.exec();

                    } /CLOSE FUNCTION INVOKEMPDDIALOGWINDOW/
                    @

                    If I try to do it in the form constructor, it tells me invalid use of incomplete type struct pushbutton as well as forward declaration of struct pushbutton.

                    @
                    ui->buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
                    @

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mchris357
                      wrote on last edited by
                      #12

                      I figured it out. It was because QPushButton wasn't included in any of the headers in the #include directives. I included it and it works perfectly fine.

                      Thanks!!!!!!

                      1 Reply Last reply
                      0
                      • MhM93M Offline
                        MhM93M Offline
                        MhM93
                        wrote on last edited by MhM93
                        #13

                        @mchris357
                        Hi. I have a problem the same as you. How do you solve your problem? I also have a dialog in my application and I used input panel. when the qdialog show and I want to type in my textbox the input panel appears but the buttons not work. When I googling all pages says because the dialog is modal and should always in top widget so the input panel not work. How do you solve it and can use input panel in your dialog?

                        H.Ghassami

                        Ni.SumiN 1 Reply Last reply
                        0
                        • MhM93M MhM93

                          @mchris357
                          Hi. I have a problem the same as you. How do you solve your problem? I also have a dialog in my application and I used input panel. when the qdialog show and I want to type in my textbox the input panel appears but the buttons not work. When I googling all pages says because the dialog is modal and should always in top widget so the input panel not work. How do you solve it and can use input panel in your dialog?

                          Ni.SumiN Offline
                          Ni.SumiN Offline
                          Ni.Sumi
                          wrote on last edited by Ni.Sumi
                          #14

                          @MhM93

                          If it is the same problem, thy have given already the solution . It got solved for them just by including #include <QPushButton>. Try it in your case, Also it might problem og show() / exec(). Please Ckeck this

                          If it did not solve your problem, please start a new thread, saying your problem.

                          1 Reply Last reply
                          2
                          • MhM93M Offline
                            MhM93M Offline
                            MhM93
                            wrote on last edited by
                            #15

                            @Ni-Sumi
                            really thanks. It solved:

                            1. Modal dialogs are started with exec(), they block the program flow while a nested event loop runs.
                            2. Modeless dialogs are started with show(), they do not block the program flow.

                            From http://www.qtforum.org/article/14285/modeless-dialog.html
                            I use this code :

                             MyDialog *d=new MyDialog(this);
                               d->show();
                               d->raise();
                            

                            instead of this code:

                            MyDialog *d=new MyDialog(this);
                               d.exec();
                            

                            H.Ghassami

                            1 Reply Last reply
                            1

                            • Login

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