[英]Change the thickness of HLine/VLine in Qt Designer
When I am trying to develop a simple UI, to make a visible separation between widgets I decided to use lines.当我尝试开发一个简单的 UI 时,为了在小部件之间进行可见的分隔,我决定使用线条。 I could use them, but when I try to change the thickness of them it didn't work.我可以使用它们,但是当我尝试改变它们的厚度时它不起作用。 And also the lines drawn are incomplete.而且画的线也不完整。 I changed the lineWidth property to change the thickness.我更改了 lineWidth 属性以更改粗细。 This is the demonstration of how I did it.这是我如何做到的演示。
Has someone got any experience about this?有人有这方面的经验吗? Can someone show me what I am doing wrong, and how to do it properly?有人可以告诉我我做错了什么,以及如何正确地做吗?
[ NB : the solution given below assumes the default Fusion widget-style is being used. [注意:下面给出的解决方案假定正在使用默认的 Fusion 小部件样式。 Some other custom styles may impose their own settings, which could very likely produce different results ]其他一些自定义样式可能会强加自己的设置,这很可能会产生不同的结果]
There are two separate issues here:这里有两个单独的问题:
Firstly, to get the desired thickness, you must adjust the following properties of the line:首先,要获得所需的粗细,必须调整线条的以下属性:
Secondly, to join horizontal and vertical lines so they form a T-junction, you must set the vertcal and/or horizontal spacing to zero for the layouts containing the relevant lines, and then set the stylesheet margins of the neighbouring widgets to restore the spacing wherever needed.其次,要连接水平线和垂直线以形成 T 形连接,您必须将包含相关线的布局的垂直和/或水平间距设置为零,然后设置相邻小部件的样式表边距以恢复间距任何需要的地方。 To illustrate this, I have added below a simple Qt Designer example.为了说明这一点,我在下面添加了一个简单的 Qt Designer 示例。 This sets the vertical spacing of the main grid-layout to zero, and also sets the margin-bottom of the top widget, and the margin-top of the two bottom widgets to the default spacing of the layout:这会将主网格布局的垂直间距设置为零,并将顶部小部件的 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.