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 dont close the dialog window if Ok in ButtonBox is clicked but some condition is not true
Forum Updated to NodeBB v4.3 + New Features

How dont close the dialog window if Ok in ButtonBox is clicked but some condition is not true

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 2.6k 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.
  • M Offline
    M Offline
    mark_ua_1999
    wrote on last edited by
    #1

    If the WidgetCell will empty when I press OK it closes, but I would like it doesn't close, hope your ideas help me to resolve the problem, thanks.
    0_1510418406469_Capture10.PNG my code

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #2

      Hi,

      You need to control in real time your QLineEdits (with textEdited() signal I presume)
      checking the validity of them in the slot method and enabled the OK button accordingly:

      QPushButton * okBut=ui->buttonBox->button(QDialogButtonBox::Ok);
      if(valid) // all the fields are valid
        okBut->setEnabled(true);
      else
        okBut->setEnabled(false);
      

      You problably also need to set the OK button to false (disabled) when the dialog show up.

      M 1 Reply Last reply
      2
      • M mpergand

        Hi,

        You need to control in real time your QLineEdits (with textEdited() signal I presume)
        checking the validity of them in the slot method and enabled the OK button accordingly:

        QPushButton * okBut=ui->buttonBox->button(QDialogButtonBox::Ok);
        if(valid) // all the fields are valid
          okBut->setEnabled(true);
        else
          okBut->setEnabled(false);
        

        You problably also need to set the OK button to false (disabled) when the dialog show up.

        M Offline
        M Offline
        mark_ua_1999
        wrote on last edited by
        #3

        @mpergand thanks,Yes you are right I do it in a such way
        connect(line, SIGNAL(textChanged(const QString &)), this, SLOT(DBsearching(const QString &)));
        void Dialog::DBsearching(const QString & s)
        {
        for(int row = 0; row<ui->tableWidget->rowCount();row++)
        {
        QLineEdit l = ui->tableWidget->cellWidget(row,2)->findChild<QLineEdit>();
        if(!true_city(l))
        {
        ui->buttonBox->setEnabled(false);
        return;
        }
        }
        ui->buttonBox->setEnabled(true);
        return;
        }

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kenchan
          wrote on last edited by
          #4

          So, is your issue/question resolved or not? If so please mark the post as solved.

          M 1 Reply Last reply
          0
          • K kenchan

            So, is your issue/question resolved or not? If so please mark the post as solved.

            M Offline
            M Offline
            mark_ua_1999
            wrote on last edited by
            #5

            @kenchan The question is resolved (what to click to mark as resolved could you help)

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kenchan
              wrote on last edited by
              #6

              There should be a menu item to set the post as resolved in the "Topic Tools" menu drop down on the right of the reply and other buttons.
              Usually under your original post.

              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