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. [Solved] QMessagebox that cannot be closed by user?

[Solved] QMessagebox that cannot be closed by user?

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

    Hi,
    I am displaying a QMessageBox to the user in a situation, where I want to have control when the message box can be closed.
    It would not be a good UX if I kept the close & OK buttons & implemented some function to ignore them, because the user would then be expecting the window to close. So my requirement is:

    1. Remove close button
    2. Remove the OK button
    3. Make it impossible for the user to be able to close the message box

    Here is the code:

    @ QMessageBox *msg = new QMessageBox();
    msg->setText("My Text");
    msg->setWindowTitle("My Title");
    msg->show();
    while(condition)
    {
    //some stuff
    }
    msg->close();
    delete msg;@

    I tried by setting the windowflags, but instead removing close button, it added minimise & maximise buttons.
    Any suggestions?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      In that case, why not just show something like a frameless QLabel ?

      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
      • CAD_codingC Offline
        CAD_codingC Offline
        CAD_coding
        wrote on last edited by
        #3

        Hi SGaist,
        Can you tell me how to get a frameless QLabel?
        Some code please?
        Because when I replace QMessageBox with QLabel in above code I am getting minimise, maximise & close buttons as well.
        Somehow the window flags just dont work...

        1 Reply Last reply
        0
        • Y Offline
          Y Offline
          yhu420
          wrote on last edited by
          #4

          Humm maybe @#include <QLabel>
          QLabel test;
          test.show();@

          Ps: this is not going to look nice..

          1 Reply Last reply
          0
          • CAD_codingC Offline
            CAD_codingC Offline
            CAD_coding
            wrote on last edited by
            #5

            Yes, That Is why I am asking about QMessageBox... :)

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              IIRC, using Qt::FramelessWindowHint

              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

              • Login

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