Qt World Summit: Submit your Presentation

[Solved] QMessagebox that cannot be closed by user?

  • 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");
    //some stuff
    delete msg;@

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

  • Lifetime Qt Champion


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

  • 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...

  • Humm maybe @#include <QLabel>
    QLabel test;

    Ps: this is not going to look nice..

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

  • Lifetime Qt Champion

    IIRC, using Qt::FramelessWindowHint

Log in to reply