【问题标题】:Changing thickness of a line in python qtdesigner在python qtdesigner中改变线条的粗细
【发布时间】:2022-07-05 20:15:55
【问题描述】:

当我尝试开发一个简单的 UI 时,为了在小部件之间进行可见的分隔,我决定使用线条。我可以使用它们,但是当我尝试改变它们的厚度时它不起作用。而且画的线也不完整。我更改了 lineWidth 属性以更改粗细。这是我如何做到的演示。

有人有这方面的经验吗?有人可以告诉我我做错了什么以及如何正确地做吗?

【问题讨论】:

    标签: python qt-designer


    【解决方案1】:

    [NB下面给出的解决方案假定正在使用默认的 Fusion 小部件样式。其他一些自定义样式可能会强加自己的设置,这很可能会产生不同的结果]


    这里有两个不同的问题:

    首先,要获得所需的粗细,必须调整线条的以下属性:

    • 将 frameShadow 设置为 Sunken 或 Raised
    • 将 lineWidth 设置为零(这是获得准确所需的厚度所必需的,否则会增加总值)
    • 将 midLineWidth 设置为所需的粗细(例如 10)
    • 将 minimumHeight(或 minimumWidth,对于垂直线)设置为与上述相同的值

    其次,要连接水平线和垂直线以形成 T 形接头,您必须将包含相关线的布局的垂直和/或水平间距设置为零,然后将相邻小部件的样式表边距设置为在需要的地方恢复间距。为了说明这一点,我在下面添加了一个简单的 Qt Designer 示例。这会将主网格布局的垂直间距设置为零,并将顶部小部件的 margin-bottom 和两个底部小部件的 margin-top 设置为布局的默认间距:

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>Form</class>
     <widget class="QWidget" name="Form">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>400</width>
        <height>300</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>Form</string>
      </property>
      <layout class="QGridLayout" name="gridLayout">
       <property name="verticalSpacing">
        <number>0</number>
       </property>
       <item row="2" column="1">
        <widget class="Line" name="line_2">
         <property name="minimumSize">
          <size>
           <width>10</width>
           <height>0</height>
          </size>
         </property>
         <property name="lineWidth">
          <number>0</number>
         </property>
         <property name="midLineWidth">
          <number>10</number>
         </property>
         <property name="orientation">
          <enum>Qt::Vertical</enum>
         </property>
        </widget>
       </item>
       <item row="1" column="0" colspan="3">
        <widget class="Line" name="line">
         <property name="minimumSize">
          <size>
           <width>0</width>
           <height>10</height>
          </size>
         </property>
         <property name="lineWidth">
          <number>0</number>
         </property>
         <property name="midLineWidth">
          <number>10</number>
         </property>
         <property name="orientation">
          <enum>Qt::Horizontal</enum>
         </property>
        </widget>
       </item>
       <item row="2" column="0">
        <widget class="QLabel" name="label_2">
         <property name="styleSheet">
          <string notr="true">background: white; margin-top: 6px</string>
         </property>
         <property name="frameShape">
          <enum>QFrame::StyledPanel</enum>
         </property>
        </widget>
       </item>
       <item row="2" column="2">
        <widget class="QLabel" name="label_3">
         <property name="styleSheet">
          <string notr="true">background: white; margin-top: 6px</string>
         </property>
         <property name="frameShape">
          <enum>QFrame::StyledPanel</enum>
         </property>
        </widget>
       </item>
       <item row="0" column="0" colspan="3">
        <widget class="QLabel" name="label">
         <property name="styleSheet">
          <string notr="true">background: white; margin-bottom: 6px</string>
         </property>
         <property name="frameShape">
          <enum>QFrame::StyledPanel</enum>
         </property>
        </widget>
       </item>
      </layout>
     </widget>
     <resources/>
     <connections/>
    </ui>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-17
      • 1970-01-01
      • 2018-02-02
      • 1970-01-01
      相关资源
      最近更新 更多