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. mac: QMessageBox::addButton() makes them left justified?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 1.4k Views 2 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.
  • D Offline
    D Offline
    davecotter
    wrote on last edited by davecotter
    #1

    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

    jsulmJ 1 Reply Last reply
    0
    • D Offline
      D Offline
      davecotter
      wrote on last edited by
      #9

      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

      1 Reply Last reply
      0
      • D davecotter

        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

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @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?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • D Offline
          D Offline
          davecotter
          wrote on last edited by davecotter
          #3

          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

          1 Reply Last reply
          0
          • D Offline
            D Offline
            davecotter
            wrote on last edited by
            #4

            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.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              davecotter
              wrote on last edited by
              #5

              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 :(

              J.HilkJ 1 Reply Last reply
              0
              • D davecotter

                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 :(

                J.HilkJ Online
                J.HilkJ Online
                J.Hilk
                Moderators
                wrote on last edited by
                #6

                @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.


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                2
                • D Offline
                  D Offline
                  davecotter
                  wrote on last edited by
                  #7

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

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

                    Hi,

                    Did you check QDialogButtonBox ?

                    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
                    0
                    • D Offline
                      D Offline
                      davecotter
                      wrote on last edited by
                      #9

                      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

                      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