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. Center Text and Buttons in QMessageBox

Center Text and Buttons in QMessageBox

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

    Hi,
    I'm fairly new using the QMessageBox class and have a question about how to align the text and buttons. I'm using the following code to create a message box and would like the text and box to be centered but when the box is created the text and button are displayed on the right-hand side of the box. I added the html center code but that didn't help with the text. Not sure what to do about the button. Any ideas? Maybe I shouldn't be using QMessageBox? I've searched through the QMessageBox class description and can't find anything on alignment.

    @ //SHOW POP-UP WHEN SAVE COMPLETE
    QMessageBox msgBox;
    msgBox.setText("<center>Machine Configuration Saved</center>");
    msgBox.setWindowTitle("System Configurator");
    msgBox.addButton(QMessageBox::Ok);
    msgBox.exec();@

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mohsen
      wrote on last edited by
      #2

      Hi,
      @msgBox.setText("<p align='center'>First Line<br>"
      "Second Line<br>"
      "Thirth Line</p>");@

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        Wether the buttons are centered is determined from the current style and is therefore platform dependend.

        The text can be centered as shown by mohsen.

        The icon is on the left side and has always reserved some space so the text is not completely aligned in the center as there's some phantom icon on the left (that may be changed by explicitly setting a 0x0 size icon, I did not test it).

        So, in your case, I would go with a handcrafted message box (use designer!) with a label for the title, another label for the text and the buttons in a layout.

        http://www.catb.org/~esr/faqs/smart-questions.html

        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