Removing Close button from QMessageBox



  • How Can I remove Close button ([x] on the top right corner) from QMessageBox.



  • Hi @NIXIN

    try this,

    messageBox.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
    


  • tried, it doesn't work



  • Try this...Found on google and worked in my case( Windows 10).

    QMessageBox* msgBox = new QMessageBox(QMessageBox::Question,
                                           "This is the title",
                                           "This is the text",
                                           QMessageBox::Yes | QMessageBox::No, this,
                                           Qt::FramelessWindowHint);
     msgBox->exec();
    

  • Moderators

    What @Ni-Sumi said works for me on Windows 7.

        QMessageBox mb;
        mb.setText("Some text");
        mb.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
        mb.exec();
    


  • Hi,

    Which OS are u using and Qt version.?.

    As mentioned by @Ni-Sumi and @Wieland

    The code provided is working in Windows 8.1 and ubuntu 14.04 version Which i am using.

    QMessageBox mb;
    mb.setText("Some text");
    mb.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
    mb.exec();

    QMessageBox* msgBox = new QMessageBox(QMessageBox::Question,
    "This is the title",
    "This is the text",
    QMessageBox::Yes | QMessageBox::No, this,
    Qt::FramelessWindowHint);
    msgBox->exec();

    Thanks,



  • Hi,

    Can u provide the code snippet, so the users in the forum will come to know the issue.
    and provide the solution.

    Thanks,



  • @NIXIN
    Pradeep code is right, you should try once again and remember it must only ''setWindowFlags' otherwise overwrite it.
    QMessageBox messageBox;
    messageBox.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
    messageBox.exec();


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.