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. QLayout margin through stylesheet [solved]
Forum Updated to NodeBB v4.3 + New Features

QLayout margin through stylesheet [solved]

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 6.2k 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.
  • R Offline
    R Offline
    redschmidt
    wrote on last edited by
    #1

    Hey all,

    I want to set the margin of all QLayout in my application to zero. There exists already a bug entry for this ("Bug 22862":https://bugreports.qt-project.org/browse/QTBUG-22862). However I can not wait until it is fixed. Does anyone has a solution, or a workaround? I would like to avoid setting margins for every Layout.

    Tahnk you,
    the red-schmidt

    [edit: declared solved]

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      since QLayout classes are not deriving from QWidget they wont be polished by the style and i doubt they will ever be.
      You would need to create a property on your widget which sets the margin on the layout then.

      For example:
      class:
      @
      class MyWidget : public QWidget
      {
      Q_OBJECT
      Q_PROPERTY(int LayoutMargins READ ... WRITE setLayoutMargins DESIGNABLE true )
      public:
      ...

      void setLayoutMargins(int margins)
      {
             if( margins >= 0 )
                  layout->setContentsMargins( margins, margins, margins, margins );
      }
      

      };
      @
      qss:
      @
      MyWidget {
      qproperty-LayoutMargins: 0;
      }
      @

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • R Offline
        R Offline
        redschmidt
        wrote on last edited by
        #3

        Thank you for the hint.

        I had a similar idea, but would like to set all Layouts in my application at one place. Creating a basic widget using this solution and inheriting from that class would cause trouble whenever I want to inherit from another Qt-Widget.

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          i haven't tried this ... it's just a quick shot out of my mind:
          @
          //initialize your layouts here
          class InitializerWidget : public virtual QWidget
          {
          Q_OBJECT
          Q_PROPERTY( .... )
          public:
          ....
          };

          //your derived widget which uses layouts from InitializerWidget class
          class MyWidget : public InitializerWidget, public QLineEdit
          {
          ...
          };
          @

          Note the virtual inheritance.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • R Offline
            R Offline
            redschmidt
            wrote on last edited by
            #5

            yeah. That works.
            Thank you :)

            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