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. Takes 2 clicks of OK button to close Messag Box if Message Box originated from button press
Forum Updated to NodeBB v4.3 + New Features

Takes 2 clicks of OK button to close Messag Box if Message Box originated from button press

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 5 Posters 6.3k 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.
  • O Offline
    O Offline
    owent
    wrote on last edited by
    #8

    I found that if I add line :-

    msgBox->setWindowModality(Qt::NonModal);
    

    then 2-click issue goes away ... but why? I want it to be modal (message box defaults to modal it appears) so this "fix" does not really help me.

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

      if you want a modal dialog you should use the exec() function if the show() functions returns immediately and is for use with non-modal dialogs. that is why you must call setWindowModality() separately.
      The easiest way to message boxes is to use the static functions directly but then ,each to his own :-).

      1 Reply Last reply
      0
      • O Offline
        O Offline
        owent
        wrote on last edited by
        #10

        The problem is I cannot use the exec() or show() even (without setting modality to nonModal) because for some reason having modalwindow is requiring 2-clicks to close the window. Only way I can have a window that comes up active and allows close on 1 click is to use show() and making the call I mentioned above to set non modal

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

          very strange? where are you calling the connect function, in the constructor of the main window?
          If you want it to be modal why not create it on the stack and use the exec() function to put it up? Then it will be modal and get deleted when it is dismissed. I am afraid I am missing your objective with the message box.

          1 Reply Last reply
          0
          • O Offline
            O Offline
            owent
            wrote on last edited by
            #12

            What I am trying to point out is that if dialog is MODAL then for some weird reason it does NOT WORK in that I have to click (touch screen) OK twice to close the dialog. I have tried msg box defined on stack .. but exec() is by definition modal and so my "need 2 clicks to close OK message box" issue still persists. I am running on linux device not windows btw QT 5.9.

            // Have tried without parent also
            QMessageBox msgBox(this); 
            
            msgBox.setWindowTitle("");
            msgBox.setText("Window Title");
            msgBox.setFont(fontBold);
            msgBox.setStyleSheet(QString::fromUtf8("background-color: rgb(0, 75, 141); color: white; "));
            
            msgBox.setStandardButtons(QMessageBox::Ok);
            QObject::connect(msgBox.button(QMessageBox::Ok), SIGNAL(pressed()), &msgBox, SLOT(close()));
            msgBox.button(QMessageBox::Ok)->setFont(fontBold);
            msgBox.button(QMessageBox::Ok)->setMinimumSize(QSize(70*HMI_SCALE, 40*HMI_SCALE));
            
            msgBox.setInformativeText("Test Info");
            
            // Close box after 30s if left open
            QTimer *mTmr = new QTimer(&msgBox);
            mTmr->setInterval(CLOSE_WINDOW_MS);
            mTmr->setSingleShot(true);
            connect(mTmr, SIGNAL(timeout()), &msgBox, SLOT(close()));
            mTmr->start();
            
            msgBox.exec() ;
            
            1 Reply Last reply
            0
            • K Offline
              K Offline
              kenchan
              wrote on last edited by kenchan
              #13

              OK great. So, you are not using the static functions for the message box because you want to style it etc.
              However, with the code you just posted I think the connect is redundant because it will close when the user closes it or the timer fires.
              I tried your code on a mac (not touch though) and did not see the issue you refer to. I will give it a try on a windows machine which has touch later.

              All I can say is you may have found a bug in the touch screen related behaviour on the linux platform, so you could email the interest mailing list or post a bug report about it and see what response you get.

              Good luck

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

                OK, in case you are interested...
                I tried the code on my windows machine which has a touch screen and touch pad, it worked fine without the issue you are describing.

                Let's hope someone else with a Linux setup similar to yours can give you some insight into what is going on.

                1 Reply Last reply
                0
                • JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #15

                  @owent Just OOI, you have tried without your code for closing the message box after a delay, haven't you?

                  1 Reply Last reply
                  0
                  • O Offline
                    O Offline
                    owent
                    wrote on last edited by
                    #16

                    The 2-click issue disappears if I use clicked() for the button connection instead of pressed() ... debug tells me that the pressed signal is NOT being emitted twice though, so no idea why using pressed() would have this side-effect. The reason I was using pressed() instead of clicked() was because the clicked() was not responsive, as though focus was being lost between the pressed and release actions. Maybe I have an issue with the touch screen itself ..

                    J.HilkJ 1 Reply Last reply
                    0
                    • O owent

                      The 2-click issue disappears if I use clicked() for the button connection instead of pressed() ... debug tells me that the pressed signal is NOT being emitted twice though, so no idea why using pressed() would have this side-effect. The reason I was using pressed() instead of clicked() was because the clicked() was not responsive, as though focus was being lost between the pressed and release actions. Maybe I have an issue with the touch screen itself ..

                      J.HilkJ Online
                      J.HilkJ Online
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #17

                      @owent

                      copied from the source code:

                      \o pressed() is emitted when the left mouse button is pressed while
                          the mouse cursor is inside the button.
                          \o released() is emitted when the left mouse button is released.
                          \o clicked() is emitted when the button is first pressed and then
                          released, when the shortcut key is typed, or when click() or
                          animateClick() is called.
                      

                      -> pressed can only be emited by the left mousebutton event, whereas clicked can also depend on click(), and IIRC that one gets also checked when the focus changes.


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      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