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. Button not filling Rectangle
Forum Updated to NodeBB v4.3 + New Features

Button not filling Rectangle

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 611 Views
  • 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.
  • Bilal_KhanB Offline
    Bilal_KhanB Offline
    Bilal_Khan
    wrote on last edited by Bilal_Khan
    #1

    I want the button's height to be matched with rectangle's height but there is a space remaining while console showing same height for both components: (I have tried different methods but the result is same)

    Rectangle {
                color: "red"
                width: 50
                height: 30
    
                Component.onCompleted:  console.log(height, er.height)    // 30, 30
    
                Button {
                    id: er
                    text: "OK"
                    anchors.fill: parent
                }
            }
    

    button.png
    Note: Actually I need to give background to row-of-buttons but with not so much space in rectangle and the row ..

    J.HilkJ 1 Reply Last reply
    0
    • Bilal_KhanB Bilal_Khan

      I want the button's height to be matched with rectangle's height but there is a space remaining while console showing same height for both components: (I have tried different methods but the result is same)

      Rectangle {
                  color: "red"
                  width: 50
                  height: 30
      
                  Component.onCompleted:  console.log(height, er.height)    // 30, 30
      
                  Button {
                      id: er
                      text: "OK"
                      anchors.fill: parent
                  }
              }
      

      button.png
      Note: Actually I need to give background to row-of-buttons but with not so much space in rectangle and the row ..

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      @Bilal_Khan

      what version of QtQuick.Controls are you using ? because with 2.15 I get
      cbb77ef4-637f-4960-9c41-ea2de91612a9-image.png

      not the really big borders top and bottom that you get, but still with border (1 px around ), I'm not sure where that is from

      but you can get around it by adding

      anchors.margins: -1

      to your button


      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
      0
      • Bilal_KhanB Offline
        Bilal_KhanB Offline
        Bilal_Khan
        wrote on last edited by Bilal_Khan
        #3

        Thanks @J-Hilk . Sorry I forgot to mention that I am using "Material" and by removing this line I get the desired result:

         QQuickStyle::setStyle("Material");
        

        Why material button is behaving like that? and how to get around this problem?

        J.HilkJ 1 Reply Last reply
        0
        • Bilal_KhanB Bilal_Khan

          Thanks @J-Hilk . Sorry I forgot to mention that I am using "Material" and by removing this line I get the desired result:

           QQuickStyle::setStyle("Material");
          

          Why material button is behaving like that? and how to get around this problem?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @Bilal_Khan I'm not entirely sure, but I think one of the features of material style (buttons) is the adjustment of the hight in relation to the font size


          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
          0
          • S Offline
            S Offline
            Soheil
            wrote on last edited by Soheil
            #5

            It's because the material style sets non-zero values for xxxInset properties.

            Set leftInset, rightInset, topInset, bottomInset values to 0 and the button appears to fill its parent.

            1 Reply Last reply
            1

            • Login

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