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 position buttons on QMessageBox?
Qt 6.11 is out! See what's new in the release blog

How to position buttons on QMessageBox?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.5k 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.
  • E Offline
    E Offline
    Enrique82
    wrote on last edited by Enrique82
    #1

    When execute this code, the buttons appears on the rigth.
    How can I center the buttons on QMessageBox?

    Captura.PNG

    QMessageBox msgBox;
    msgBox.setText("Detener proceso?");
    msgBox.setWindowFlags(Qt::FramelessWindowHint);
    QPushButton *yesButton = msgBox.addButton("Si", QMessageBox::ActionRole);
    QPushButton *noButton = msgBox.addButton("No", QMessageBox::ActionRole);
    msgBox.setStyleSheet("QMessageBox QPushButton{"
                         "font-family: Lato Heavy; "
                         "font-weight: bold; "
                         "font-size: 20pt; "
                         "background-color: rgb(50, 50, 50, 255);"
                         "color: white;"
                         "}");
    
    msgBox.setStyleSheet("QMessageBox QLabel{"
                         "color: black; "
                         "}");
    
    msgBox.setStyleSheet("QMessageBox{"
                         "font-family: Lato Heavy; "
                         "font-weight: bold; "
                         "font-size: 15pt; "
                         "background-color: rgb(200, 200, 200, 255);"
                         "}");
    msgBox.exec();
    if ((QPushButton*)msgBox.clickedButton() == yesButton) {
        return true;
    } else if ((QPushButton*)msgBox.clickedButton() == noButton) {
        return false;
    }
    

    Thanks.

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

      Hi,

      You can do simpler: QDialogButtonBox. That class does the work for you.

      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
      3

      • Login

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