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. Buttons and icons align left?
Forum Updated to NodeBB v4.3 + New Features

Buttons and icons align left?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 4 Posters 1.6k 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.
  • J Offline
    J Offline
    jialuo
    wrote on last edited by
    #1

    27ebd04d-3fbe-4131-861e-1eb917fce75b-image.png
    How to achieve left alignment of buttons and icons? like checkBox

    309eb831-40bd-4346-9da1-b50d9439fc54-image.png

    JoeCFDJ 1 Reply Last reply
    0
    • J jialuo

      @ankou29666 I mean customize the layout inside the button.

      ekkescornerE Offline
      ekkescornerE Offline
      ekkescorner
      Qt Champions 2016
      wrote on last edited by
      #6

      @jialuo see https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-button
      your content item perhaps Row of Icon and Text

      ekke ... Qt Champion 2016 | 2024 ... mobile business apps
      5.15 --> 6.9 https://t1p.de/ekkeChecklist
      QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by A Former User
        #2

        Hi

        I'd anchor the icons to the left with appropriate left margin.

        Something like

        Rectangle
        {
            id: parentRect
            anchors, height, and width: whatever you want
        
            Icon
            {
                id: icon
                anchors.left: parent.left
                anchors.leftMargin: someValue
                other anchors, height and width: as you need
            }
        
            Label
            {
                anchors.left: icon.right
                anchors.leftMargin: someValue
            }
        }
        
        J 1 Reply Last reply
        0
        • J jialuo

          27ebd04d-3fbe-4131-861e-1eb917fce75b-image.png
          How to achieve left alignment of buttons and icons? like checkBox

          309eb831-40bd-4346-9da1-b50d9439fc54-image.png

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #3

          @jialuo show your button code

          J 1 Reply Last reply
          0
          • JoeCFDJ JoeCFD

            @jialuo show your button code

            J Offline
            J Offline
            jialuo
            wrote on last edited by
            #4

            @JoeCFD ```
            Column{

            Button{
                height: 30
                width: 100
                icon.source:"./Image/fluent_star_filled.svg"
                spacing: 10
                text: "未分类"
            }
            Button{
                height: 30
                width: 100
                icon.source:"./Image/fluent_star_filled.svg"
                spacing: 10
                text: "未标签"
            }
            Button{
                height: 30
                width: 100
                icon.source:"./Image/fluent_star_filled.svg"
                spacing: 10
                text: "标签管理"
            }
            Button{
                height: 30
                width: 100
                icon.source:"./Image/fluent_star_filled.svg"
                spacing: 10
                text: "回收站"
            }
            

            }

            JoeCFDJ 1 Reply Last reply
            0
            • ? A Former User

              Hi

              I'd anchor the icons to the left with appropriate left margin.

              Something like

              Rectangle
              {
                  id: parentRect
                  anchors, height, and width: whatever you want
              
                  Icon
                  {
                      id: icon
                      anchors.left: parent.left
                      anchors.leftMargin: someValue
                      other anchors, height and width: as you need
                  }
              
                  Label
                  {
                      anchors.left: icon.right
                      anchors.leftMargin: someValue
                  }
              }
              
              J Offline
              J Offline
              jialuo
              wrote on last edited by
              #5

              @ankou29666 I mean customize the layout inside the button.

              ekkescornerE 1 Reply Last reply
              0
              • J jialuo

                @ankou29666 I mean customize the layout inside the button.

                ekkescornerE Offline
                ekkescornerE Offline
                ekkescorner
                Qt Champions 2016
                wrote on last edited by
                #6

                @jialuo see https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-button
                your content item perhaps Row of Icon and Text

                ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                5.15 --> 6.9 https://t1p.de/ekkeChecklist
                QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                1 Reply Last reply
                0
                • J jialuo

                  @JoeCFD ```
                  Column{

                  Button{
                      height: 30
                      width: 100
                      icon.source:"./Image/fluent_star_filled.svg"
                      spacing: 10
                      text: "未分类"
                  }
                  Button{
                      height: 30
                      width: 100
                      icon.source:"./Image/fluent_star_filled.svg"
                      spacing: 10
                      text: "未标签"
                  }
                  Button{
                      height: 30
                      width: 100
                      icon.source:"./Image/fluent_star_filled.svg"
                      spacing: 10
                      text: "标签管理"
                  }
                  Button{
                      height: 30
                      width: 100
                      icon.source:"./Image/fluent_star_filled.svg"
                      spacing: 10
                      text: "回收站"
                  }
                  

                  }

                  JoeCFDJ Offline
                  JoeCFDJ Offline
                  JoeCFD
                  wrote on last edited by JoeCFD
                  #7

                  @jialuo
                  add this to each button

                      contentItem: Label {
                          anchors.fill: parent
                          Row {
                              Image {
                                  id: myImage
                                  height: root.height
                                  width:  root.height
                                  source: "./Image/fluent_star_filled.svg"
                              }
                  
                              Text {
                                  text: root.text
                                  height: root.height
                                  width:  root.availableWidth
                                  color: "white"
                                  horizontalAlignment: Text.AlignLeft
                                  verticalAlignment: Text.AlignVCenter
                              }
                          }
                      }
                  

                  Better to create a customized button and you may have more settings like font.

                  J 1 Reply Last reply
                  0
                  • JoeCFDJ JoeCFD

                    @jialuo
                    add this to each button

                        contentItem: Label {
                            anchors.fill: parent
                            Row {
                                Image {
                                    id: myImage
                                    height: root.height
                                    width:  root.height
                                    source: "./Image/fluent_star_filled.svg"
                                }
                    
                                Text {
                                    text: root.text
                                    height: root.height
                                    width:  root.availableWidth
                                    color: "white"
                                    horizontalAlignment: Text.AlignLeft
                                    verticalAlignment: Text.AlignVCenter
                                }
                            }
                        }
                    

                    Better to create a customized button and you may have more settings like font.

                    J Offline
                    J Offline
                    jialuo
                    wrote on last edited by jialuo
                    #8

                    @JoeCFD Thanks I figured out how to do it, but chronologically I marked ekkescorner as the answer.

                    1 Reply Last reply
                    0
                    • J jialuo has marked this topic as solved on

                    • Login

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