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. Where is QLayout property leftMargin
Forum Updated to NodeBB v4.3 + New Features

Where is QLayout property leftMargin

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 495 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.
  • A.v.OA Offline
    A.v.OA Offline
    A.v.O
    wrote on last edited by
    #1

    Question

    Where is QLayout property leftMargin in the code?

    Situation

    When I got the ui-file as described below.
    The QFormLayout has clearly a leftMargin property.
    But when I set this property from the code, like:

    Root->layout()->setProperty("leftMargin", 33);
    

    This is not working.
    There must be some magic at work here.

    Expected

    I expected actually the QMargins typed property to behave like the QRect typed ones.

     <property name="contentMargins">
      <margins>
        <left>6</left>
        <top>6</top>
        <right>6</right>
        <bottom>6</bottom>
     </margins>
    

    Has anyone an idea why this is?

    Maybe an irreversible mistake made in an earlier version :(

    The mentioned Ui-file

     <?xml version="1.0" encoding="UTF-8"?>
     <ui version="4.0">
      <class>Form</class>
      <widget class="QWidget" name="Root">
       <property name="windowTitle">
        <string>Form</string>
       </property>
       <property name="geometry">
        <rect>
         <x>0</x>
         <y>0</y>
         <width>421</width>
         <height>100</height>
        </rect>
       </property>
       <layout class="QFormLayout" name="formLayout">
        <property name="leftMargin">
         <number>100</number>
        </property>
        <property name="topMargin">
         <number>6</number>
        </property>
        <property name="rightMargin">
         <number>6</number>
        </property>
        <property name="bottomMargin">
         <number>6</number>
        </property>
        <item row="0" column="0">
         <widget class="QLabel" name="label">
          <property name="text">
           <string>TextLabel</string>
          </property>
          <property name="buddy">
           <cstring>lineEdit</cstring>
          </property>
         </widget>
        </item>
        <item row="0" column="1">
         <widget class="QLineEdit" name="lineEdit"/>
        </item>
       </layout>
      </widget>
     </ui>
    
    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by ChrisW67
      #2

      There is no such property documented in QFormLayout or QLayout, so it is unsurprising you cannot set it that way.
      To set the individual (or all) margins use a combination of QLayout::contentsMargins() and QLayout::setContentsMargins().

      Here is an excerpt of what uic generates from your UI file:

      ...
              if (Root->objectName().isEmpty())
                  Root->setObjectName(QString::fromUtf8("Root"));
              Root->resize(421, 100);
              formLayout = new QFormLayout(Root);
              formLayout->setObjectName(QString::fromUtf8("formLayout"));
              formLayout->setContentsMargins(100, 6, 6, 6);
      ...
      

      Has anyone an idea why this is?
      Maybe an irreversible mistake made in an earlier version :(

      No, not a mistake, a design choice. QRect and QLayout are different beasts. There is also no requirement for a one-to-one mapping between the UI file XML and properties.

      A.v.OA 1 Reply Last reply
      3
      • C ChrisW67

        There is no such property documented in QFormLayout or QLayout, so it is unsurprising you cannot set it that way.
        To set the individual (or all) margins use a combination of QLayout::contentsMargins() and QLayout::setContentsMargins().

        Here is an excerpt of what uic generates from your UI file:

        ...
                if (Root->objectName().isEmpty())
                    Root->setObjectName(QString::fromUtf8("Root"));
                Root->resize(421, 100);
                formLayout = new QFormLayout(Root);
                formLayout->setObjectName(QString::fromUtf8("formLayout"));
                formLayout->setContentsMargins(100, 6, 6, 6);
        ...
        

        Has anyone an idea why this is?
        Maybe an irreversible mistake made in an earlier version :(

        No, not a mistake, a design choice. QRect and QLayout are different beasts. There is also no requirement for a one-to-one mapping between the UI file XML and properties.

        A.v.OA Offline
        A.v.OA Offline
        A.v.O
        wrote on last edited by
        #3

        @ChrisW67 said in Where is QLayout property leftMargin:

        No, not a mistake, a design choice. QRect and QLayout are different beasts. There is also no requirement for a one-to-one mapping between the UI file XML and properties.

        It seems just inconsequent having ui-file have properties on an QObject that does not exist in the code.

        By the way, I'm not using the ui-file to be compiled but using QFormBuilder with some of work-arounds to load/create modify and save ui-files from the Concept Application I'm working on.
        That is why I'm missing the properties on the layout object.

        b9994d79-d1ad-497f-8494-ffa54248d5f0-image.png

        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