Solved 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:
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:
(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
-
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
-
@davecotter Don't know about the button alignment, but regarding last question: see Qt::WindowCloseButtonHint (you need to unset it), https://doc.qt.io/qt-5/qt.html#WindowType-enum, https://doc.qt.io/qt-5/qmessagebox.html#QMessageBox-1
"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]); layoutP->setDirection(QHBoxLayout::RightToLeft); }
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:
layoutP->addSpacing(80);
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 :(
-
@davecotter
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.
-
Hi,
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