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. Set fixed margin/spacing/padding between Widgets/Layouts
QtWS25 Last Chance

Set fixed margin/spacing/padding between Widgets/Layouts

Scheduled Pinned Locked Moved Solved General and Desktop
marginsspacinglayoutswidgets
8 Posts 4 Posters 28.6k 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.
  • W Offline
    W Offline
    wrekler
    wrote on 17 Oct 2018, 21:01 last edited by
    #1

    I'm trying to figure out how to set a fixed size to margin/spacing/padding between widgets/layouts. Maybe I'm wrong. What I've is this:
    alt text

    I want to take control of that blue space in the image. I tried setting margin/spacing/padding to 0 but always there is that space!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 17 Oct 2018, 21:16 last edited by
      #2

      Hi,

      From the looks of it it seems you are using a stylesheet, is that the case ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      W 1 Reply Last reply 17 Oct 2018, 21:21
      0
      • S SGaist
        17 Oct 2018, 21:16

        Hi,

        From the looks of it it seems you are using a stylesheet, is that the case ?

        W Offline
        W Offline
        wrekler
        wrote on 17 Oct 2018, 21:21 last edited by
        #3

        @SGaist
        yes! This is .css:

        #minimaxBtn {
            border: 0px solid;
            color: #fff;
            font-weight: bold;
            font-family: Arial, sans-serif;
        }
        #closeBtn {
            border: 0px solid;
            color: #fff;
            font-family: Arial, sans-serif;
        }
        
        #minimaxBtn:hover {
            background-color: rgba(175, 175, 175, 0.50);
        }
        
        #closeBtn:hover {
            background-color: red;
        }
        #closeBtn:hover:pressed {
            background-color: rgba(206, 67, 67, 0.90);
        }
        
        #minimaxBtn:hover:pressed {
            background-color: rgba(38, 38, 38, 0.50);
        }
        
        Widget { //this is the main widget
            background-color: #3d3d3d;
        }
        
        #toolBar { //this is the widget with HBoxLayout
            background-color: rgba(206, 67, 67, 0.90);
            border: 1px solid;
            border-color: aqua;
            border-radius: 0 0 0 0;
            padding: 0px 0px 0px 0px;
        }
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 17 Oct 2018, 22:00 last edited by
          #4

          Did you already set the spacing and margin on the layout ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          W 1 Reply Last reply 18 Oct 2018, 08:51
          0
          • S SGaist
            17 Oct 2018, 22:00

            Did you already set the spacing and margin on the layout ?

            W Offline
            W Offline
            wrekler
            wrote on 18 Oct 2018, 08:51 last edited by wrekler
            #5

            @SGaist said in Set fixed margin/spacing/padding between Widgets/Layouts:

            Did you already set the spacing and margin on the layout

            Yes, I added all of them and nothing is changed!

            Widget {
                background-color: #3d3d3d;
                border: 1px solid;
                border-color: aqua;
            
                padding: 0 0 0 0;
                border-spacing: 0px 0px;
                margin: 0px;
            }
            
            #toolBar {
                background-color: rgba(206, 67, 67, 0.90);
                border: 1px solid;
                border-color: aqua;
            
                padding: 0 0 0 0;
                border-spacing: 0px 0px;
                margin: 0px;
            }
            

            I'm actually using this project as base widow to enable windows aero features:
            https://github.com/dfct/TrueFramelessWindow

            what I can see in the code is this:

            //Clear margins & spacing & add the layout to prepare for the MainAppWidget
            setContentsMargins(0, 0, 0, 0);
            setLayout(&m_Layout);
            m_Layout.setContentsMargins(0, 0, 0, 0);
            m_Layout.setSpacing(0);
            

            before adding the main widget, but what I understand that is for base aero wrapper, then I get margin in my main widget and in my toolbar, so I think this is not the problem...

            J 1 Reply Last reply 18 Oct 2018, 08:55
            0
            • W wrekler
              18 Oct 2018, 08:51

              @SGaist said in Set fixed margin/spacing/padding between Widgets/Layouts:

              Did you already set the spacing and margin on the layout

              Yes, I added all of them and nothing is changed!

              Widget {
                  background-color: #3d3d3d;
                  border: 1px solid;
                  border-color: aqua;
              
                  padding: 0 0 0 0;
                  border-spacing: 0px 0px;
                  margin: 0px;
              }
              
              #toolBar {
                  background-color: rgba(206, 67, 67, 0.90);
                  border: 1px solid;
                  border-color: aqua;
              
                  padding: 0 0 0 0;
                  border-spacing: 0px 0px;
                  margin: 0px;
              }
              

              I'm actually using this project as base widow to enable windows aero features:
              https://github.com/dfct/TrueFramelessWindow

              what I can see in the code is this:

              //Clear margins & spacing & add the layout to prepare for the MainAppWidget
              setContentsMargins(0, 0, 0, 0);
              setLayout(&m_Layout);
              m_Layout.setContentsMargins(0, 0, 0, 0);
              m_Layout.setSpacing(0);
              

              before adding the main widget, but what I understand that is for base aero wrapper, then I get margin in my main widget and in my toolbar, so I think this is not the problem...

              J Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 18 Oct 2018, 08:55 last edited by
              #6

              @wrekler you have to set the margin and spacing of the QLayout item to 0 as well, not only in the StyleSheet. I believe those are 2 different pairs of shoes.


              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
              3
              • J Offline
                J Offline
                JonB
                wrote on 18 Oct 2018, 08:57 last edited by JonB
                #7

                To clarify what @J-Hilk is saying (which I believe to be correct): a QLayout is not a QWidget and so cannot have its attributes affected via a stylesheet rule (sadly). That has to be done via explicit, back-end code.

                W 1 Reply Last reply 18 Oct 2018, 09:05
                3
                • J JonB
                  18 Oct 2018, 08:57

                  To clarify what @J-Hilk is saying (which I believe to be correct): a QLayout is not a QWidget and so cannot have its attributes affected via a stylesheet rule (sadly). That has to be done via explicit, back-end code.

                  W Offline
                  W Offline
                  wrekler
                  wrote on 18 Oct 2018, 09:05 last edited by
                  #8

                  @J.Hilk said in Set fixed margin/spacing/padding between Widgets/Layouts:

                  @wrekler you have to set the margin and spacing of the QLayout item to 0 as well, not only in the StyleSheet. I believe those are 2 different pairs of shoes.

                  @JonB said in Set fixed margin/spacing/padding between Widgets/Layouts:

                  To clarify what @J-Hilk is saying (which I believe to be correct): a QLayout is not a QWidget and so cannot have its attributes affected via a stylesheet rule (sadly). That has to be done via explicit, back-end code.

                  Here we go! That was the problem! Layout cannot be affected by a stylesheet file! Now I know how styling layout works! Thank!

                  1 Reply Last reply
                  2

                  8/8

                  18 Oct 2018, 09:05

                  • Login

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