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. How to customise a message box with no "close" button?
Forum Updated to NodeBB v4.3 + New Features

How to customise a message box with no "close" button?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 827 Views 3 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.
  • GuerrianG Offline
    GuerrianG Offline
    Guerrian
    wrote on last edited by Guerrian
    #1

    Here is what I have currently:

                QMessageBox::StandardButton reply;
                if (!saved)
                {
                    reply = QMessageBox::question(this, tr("Question"), tr("Do you want to save changes?"),
                        QMessageBox::Yes|QMessageBox::No|QMessageBox::Close);
                    if (reply == QMessageBox::Yes)
                    {
                        if (model.name == "Untitled.emx")
                            saveAs();
                        else
                            save();
                    }
                    else if (reply == QMessageBox::Close)
                        return false;
                }
                return true;
            
    

    How can I have the close option (via the "x"), but not have the "close" titled button?

    Linux Mint 18.3
    Qt 5.14.1
    Qt Creator 4.11.1

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

      Hi
      Do you mean to have it return QMessageBox::Close for 'X'
      when that button is not added?
      I don't think that is possible.

      However, remove QMessageBox::Close and put MessageBox::question in a function.
      Then look what it returns when using 'X' and simply return QMessageBox::Close to caller instead.

      GuerrianG 2 Replies Last reply
      0
      • mrjjM mrjj

        Hi
        Do you mean to have it return QMessageBox::Close for 'X'
        when that button is not added?
        I don't think that is possible.

        However, remove QMessageBox::Close and put MessageBox::question in a function.
        Then look what it returns when using 'X' and simply return QMessageBox::Close to caller instead.

        GuerrianG Offline
        GuerrianG Offline
        Guerrian
        wrote on last edited by
        #3

        @mrjj Yes, it returns 65536 when I click "x" and there's no "close" button.

        Linux Mint 18.3
        Qt 5.14.1
        Qt Creator 4.11.1

        1 Reply Last reply
        0
        • mrjjM mrjj

          Hi
          Do you mean to have it return QMessageBox::Close for 'X'
          when that button is not added?
          I don't think that is possible.

          However, remove QMessageBox::Close and put MessageBox::question in a function.
          Then look what it returns when using 'X' and simply return QMessageBox::Close to caller instead.

          GuerrianG Offline
          GuerrianG Offline
          Guerrian
          wrote on last edited by Guerrian
          #4

          @mrjj ...which is "no" (QMessageBox::No), so I guess it can't be done.

          Linux Mint 18.3
          Qt 5.14.1
          Qt Creator 4.11.1

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

            Hi,

            What is your goal ? Something like Yes/No/Cancel ? In that case, QMessageBox::Cancel would make more sense.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            GuerrianG 1 Reply Last reply
            1
            • SGaistS SGaist

              Hi,

              What is your goal ? Something like Yes/No/Cancel ? In that case, QMessageBox::Cancel would make more sense.

              GuerrianG Offline
              GuerrianG Offline
              Guerrian
              wrote on last edited by
              #6

              @SGaist said in How to customise a message box with no "close" button?:

              QMessageBox::Cancel

              Yeah that makes more sense.

              Linux Mint 18.3
              Qt 5.14.1
              Qt Creator 4.11.1

              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