mac: QMessageBox::addButton() makes them left justified?

  • when i add my own buttons to QMessageBox, they come in left justified, not right as they should be on the mac. eg: i want the dialog to look like this:

    0_1557203493227_Screen Shot 2019-05-06 at 9.07.28 PM.png

    this button happens to be an OK button so you may think to advise me to use a default button, but that's not what i want to do. i want all buttons to be CUSTOM buttons, with no automatic re-layout based on platform, and i do NOT want to use the built in roles (indeed i wish there were a "custom" role i could assign to all buttons).

    When i attempt to re-create this dialog in Qt, it looks like this:

    0_1557203598312_Screen Shot 2019-05-06 at 9.33.11 PM.png

    (i'll get to the icon later). why is the button not right justified? how do i right justify it?

    since i'm here, how do i GET RID of the "close button" (The little red dot), that is very NOT the macintosh way

  • Qt Champions 2018

    @davecotter Don't know about the button alignment, but regarding last question: see Qt::WindowCloseButtonHint (you need to unset it),,

    "When i attempt to re-create this dialog in Qt" - can you show how you're doing this?

  • i see that i can do this:

    QList<QHBoxLayout *>	list(i_qDlg.findChildren<QHBoxLayout *>());
    if (list.size() == 1) {
    	QHBoxLayout		*layoutP(list[0]);

    and that does indeed right justify things, but in REVERSE order. sigh.

    to the other hint: yes i already tried setting CustomizeWindowHint and NOT setting WindowCloseButtonHint, but it still definitely always shows the close button.

    | "can you show how you're doing this?"
    i'm just creating a QMessageBox dialog with no buttons, then calling addButton sequentially, expecting that they'll be right justified

  • since we're on the topic of button spacing i ALSO wonder why i can't add a spacer in between two buttons, like this:


    i was hoping that would work but it's ignored. i tried adding a blank button then hiding it, but the HIDE call is ignored (?) and i end up with better spacing but an empty button in between my two buttons.

  • dangit i see in the source code that QMessageBox::QMessageBox() forcibly adds "WindowCloseButtonHint", and there is no way to turn that off. I'd have to re-implement the entire dialog :(

  • Moderators

    with so much customization you want to do to your QMessageBox, it may be advisable to inherit from QDialog(the base class of QMessangeBox) and go from there.

    You should have an easier time that way.

  • i was hoping to avoid having to re-invent the wheel, which is 95% done with QMessageBox. sigh.

  • Lifetime Qt Champion


    Did you check QDialogButtonBox ?

  • yes, QDialogButtonBox doesn't have a "justify" option. i think i have to admit that the best option is to make my own dialog, free of the constraints of QMessageBox

Log in to reply

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