Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Customise Dialog button size
Forum Updated to NodeBB v4.3 + New Features

Customise Dialog button size

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 1.3k 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.
  • B Online
    B Online
    Bob64
    wrote on 11 Jun 2019, 17:13 last edited by
    #1

    I use Dialog in a few places but one thing that always strikes me is how big the buttons seem. They look out of proportion to the small amount of content that I have in the dialog sometimes.

    Is there any way that I can customise the size of the buttons? I have tried assigning a DialogButtonBox rather than relying on the default buttons. I tried setting a smaller height than the default in the DialogButtonBox but the layout goes haywire - I saw the button labels floating outside the boundary of the dialog (the buttons themselves had disappeared!). I also tried setting height in the Button objects inside the DialogButtonBox, but that was just ignored it seemed.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Shrinidhi Upadhyaya
      wrote on 12 Jun 2019, 06:06 last edited by
      #2

      Hi @Bob64 ,

      • You need to use the delegate property inside the DialogButtonBox .

      Note:- You can only use standardButtons in the delegate nothing else.

      Sample Code:-

      Dialog {
          visible: true
          title: "Dummy Dialog Box"
          width: 400
          height: 400
      
          DialogButtonBox {
              id: buttonBox
      
              width: parent.width
              height: 40
              anchors.bottom: parent.bottom
              padding: 0
              standardButtons: StandardButton.Save | StandardButton.Cancel
      
              onAccepted: console.log("Save clicked")
              onRejected: console.log("Cancel Clicked")
      
              delegate: Button {
                  id: control
      
                  width: buttonBox.width / 2
                  height: 40
                  anchors.verticalCenter: parent.verticalCenter
      
                  background: Rectangle {
                      color: control.down ? "#17a81a" : "#21be2b"
                      radius: 2
                  }
              }
          }
      }
      

      Sample Output:-

      0_1560319352110_ba1928b0-1f8d-4a14-b995-384d5d5b00db-image.png

      • You can set the height you want to the Button, in my code i have set the height to 40.

      For more information[https://doc.qt.io/qt-5/qml-qtquick-controls2-dialogbuttonbox.html#delegate-prop]

      Shrinidhi Upadhyaya.
      Upvote the answer(s) that helped you to solve the issue.

      1 Reply Last reply
      6
      • B Online
        B Online
        Bob64
        wrote on 12 Jun 2019, 21:30 last edited by
        #3

        Thank you @Shrinidhi-Upadhyaya.

        I should have mentioned that I am currently using Qt 5.9.6. In case anyone reading is in a similar position, the enums such as StandardButton.Save need to be replaced with DialogButtonBox.Save (it seems that Dialog.Save works too though it is not documented).

        You mentioned the constraint that the delegate may only be used with standardButtons. One thing I might want to do is to relabel the button. In principle all one has to do is to set the text property to the required label but I could not find an obvious way to identify the current button in the delegate and I don't know if one can make any assumptions about the order in which the delegate is invoked for each button. The nearest I could achieve was a hack whereby I test the initial value of text in a Component.onCompleted handler and set new text based on this. However, this won't be robust to internationalisation.

        1 Reply Last reply
        0

        1/3

        11 Jun 2019, 17:13

        • Login

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