Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to handle QMessageBox when user click outside of MessageBox
Forum Updated to NodeBB v4.3 + New Features

How to handle QMessageBox when user click outside of MessageBox

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
10 Posts 2 Posters 1.2k 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
    Mohan Raj
    wrote on last edited by
    #1

    hi, my problem was i have created a QMessageBox properly in raspberry pi but my problem was when i click on outside of the messagebox window application takes default as no. My need is when user click outside of the messageBox application must wont response for that event only the message box button should work at that time. Can you help me to do that. Below i have added my messageBox code

    void MainWindow::on_pushButton_Shutdown_clicked()
    {
        qDebug()<<"entered shutdown message box";
        QMessageBox msg(this);
        msg.setWindowFlags(Qt::Popup);
        msg.setStyleSheet("font: 75 20pt Liberation Serif ;");
        QPixmap pix("/home/pi/git/FIA_Validation/FIA/notification.png");
        auto newPixmap = pix.scaled(65, 65);
        msg.setIconPixmap(newPixmap);
        msg.setStyleSheet("font:16pt Arial;");
        msg.setText("Are you sure you want to power off ?");
        msg.setStandardButtons(QMessageBox::Ok | QMessageBox::No);
        msg.setDefaultButton(QMessageBox::NoButton);
        msg.setButtonText(QMessageBox::Ok , "Yes");
        msg.setButtonText(QMessageBox::No , "Go back");
        msg.setFixedWidth(500);
        if(msg.exec() == QMessageBox::Ok)
        {
            system("sudo poweroff");  //System Power Off Option
        }
        else
        {
    
        }
    
    }
    
    JonBJ 1 Reply Last reply
    0
    • M Mohan Raj

      hi, my problem was i have created a QMessageBox properly in raspberry pi but my problem was when i click on outside of the messagebox window application takes default as no. My need is when user click outside of the messageBox application must wont response for that event only the message box button should work at that time. Can you help me to do that. Below i have added my messageBox code

      void MainWindow::on_pushButton_Shutdown_clicked()
      {
          qDebug()<<"entered shutdown message box";
          QMessageBox msg(this);
          msg.setWindowFlags(Qt::Popup);
          msg.setStyleSheet("font: 75 20pt Liberation Serif ;");
          QPixmap pix("/home/pi/git/FIA_Validation/FIA/notification.png");
          auto newPixmap = pix.scaled(65, 65);
          msg.setIconPixmap(newPixmap);
          msg.setStyleSheet("font:16pt Arial;");
          msg.setText("Are you sure you want to power off ?");
          msg.setStandardButtons(QMessageBox::Ok | QMessageBox::No);
          msg.setDefaultButton(QMessageBox::NoButton);
          msg.setButtonText(QMessageBox::Ok , "Yes");
          msg.setButtonText(QMessageBox::No , "Go back");
          msg.setFixedWidth(500);
          if(msg.exec() == QMessageBox::Ok)
          {
              system("sudo poweroff");  //System Power Off Option
          }
          else
          {
      
          }
      
      }
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Mohan-Raj said in How to handle QMessageBox when user click outside of MessageBox:

      My need is when user click outside of the messageBox application must wont response for that event only the message box button should work at that time.

      That is what it normally does. It is because you added msg.setWindowFlags(Qt::Popup); that it behaves the way you report. "Popup" means "click outside closes". So don't do that!

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Mohan Raj
        wrote on last edited by
        #3

        i have a problem on removing that when i remove it, this shows with minimize and close options in frame when i click on that minimize it minimizes my whole application and also sometimes when i close the message box by using the frame option it also perform like that so please can you help me with any other options

        JonBJ 1 Reply Last reply
        0
        • M Mohan Raj

          i have a problem on removing that when i remove it, this shows with minimize and close options in frame when i click on that minimize it minimizes my whole application and also sometimes when i close the message box by using the frame option it also perform like that so please can you help me with any other options

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Mohan-Raj
          I haven't looked into it, but there are flags for removing the "furniture" buttons like "minimize", "maximize" or "close".

          1 Reply Last reply
          1
          • M Offline
            M Offline
            Mohan Raj
            wrote on last edited by
            #5

            yes, you are right but if i use these flags messageBox was not opened or pop up
            msg.setWindowFlags(Qt::WindowMinimizeButtonHint);
            msg.setWindowFlags(Qt::WindowCloseButtonHint);

            JonBJ 1 Reply Last reply
            0
            • M Mohan Raj

              yes, you are right but if i use these flags messageBox was not opened or pop up
              msg.setWindowFlags(Qt::WindowMinimizeButtonHint);
              msg.setWindowFlags(Qt::WindowCloseButtonHint);

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @Mohan-Raj
              Your code is wrong, in a couple of ways. You meant:

              msg.setWindowFlag(Qt::WindowMinimizeButtonHint, false);
              msg.setWindowFlag(Qt::WindowCloseButtonHint, false);
              

              Having said that, I don't actually find that suppresses the close button at least, Qt5 under Ubuntu Xorg. You'll have to play.

              1 Reply Last reply
              1
              • M Offline
                M Offline
                Mohan Raj
                wrote on last edited by
                #7

                but the way you gave also not working. Okay that's fine I'll play further, Thanks for your cooperation

                JonBJ 1 Reply Last reply
                0
                • M Mohan Raj

                  but the way you gave also not working. Okay that's fine I'll play further, Thanks for your cooperation

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @Mohan-Raj said in How to handle QMessageBox when user click outside of MessageBox:

                  but the way you gave also not working.

                  I suggest my code is working! (Yours just plain did wrong thing.) You could verify by qDebug() << msg.windowFlags() to check those two have indeed been switched off. Output before and after my code:

                  QFlags<Qt::WindowType>(Dialog|MSWindowsFixedSizeDialogHint|WindowTitleHint|WindowSystemMenuHint|WindowCloseButtonHint)
                  QFlags<Qt::WindowType>(Dialog|MSWindowsFixedSizeDialogHint|WindowTitleHint|WindowSystemMenuHint)
                  

                  Which shows the code works correctly, yet the message box still shows the "close" box. I don't know if that is a feature of the standard/native QMessageBox. Looks like adding

                  msg.setWindowFlag(Qt::CustomizeWindowHint, true);
                  

                  allows it to be removed.

                  M 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Mohan-Raj said in How to handle QMessageBox when user click outside of MessageBox:

                    but the way you gave also not working.

                    I suggest my code is working! (Yours just plain did wrong thing.) You could verify by qDebug() << msg.windowFlags() to check those two have indeed been switched off. Output before and after my code:

                    QFlags<Qt::WindowType>(Dialog|MSWindowsFixedSizeDialogHint|WindowTitleHint|WindowSystemMenuHint|WindowCloseButtonHint)
                    QFlags<Qt::WindowType>(Dialog|MSWindowsFixedSizeDialogHint|WindowTitleHint|WindowSystemMenuHint)
                    

                    Which shows the code works correctly, yet the message box still shows the "close" box. I don't know if that is a feature of the standard/native QMessageBox. Looks like adding

                    msg.setWindowFlag(Qt::CustomizeWindowHint, true);
                    

                    allows it to be removed.

                    M Offline
                    M Offline
                    Mohan Raj
                    wrote on last edited by
                    #9

                    @JonB Yes you are right, its working properly when i see in Debug() but in application UI output the close ,minimize or not disabled or hidden working asusual.
                    UI output
                    MESSAGEBOX.png

                    Debug Output
                    DEBUG.png

                    JonBJ 1 Reply Last reply
                    0
                    • M Mohan Raj

                      @JonB Yes you are right, its working properly when i see in Debug() but in application UI output the close ,minimize or not disabled or hidden working asusual.
                      UI output
                      MESSAGEBOX.png

                      Debug Output
                      DEBUG.png

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #10

                      @Mohan-Raj
                      Works for me under Qt5 and Xorg.
                      Obviously I don't have RPi. Are you perchance running under Wayland? If/assuming so, you probably won't be able to do much about changing stuff like this as Wayland likely doesn't allow it. Can you try under Xorg?

                      On a separate matter or if this is the case. I do not know why you want to change this stuff. Leave message boxes etc. with whatever furniture is usual, that's standard for the windowing system. If you insist, try creating your own window with as little inbuilt stuff as possible, e.g. don't use QMessageBox or Dialog style and see where you get to.

                      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