I'm trying to figure out how to make a horizontal line in Qt. This is easy to create in Designer but I want to create one programmatically. I've done some googleing and looked at the xml in a ui file but haven't been able to figure anything out.
This is what the xml from the ui file looks like:
<widget class="Line" name="line">
<property name="geometry">
<rect>
<x>150</x>
<y>110</y>
<width>118</width>
<height>3</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
A horizontal or vertical line is just a QFrame
with some properties set. In C++, the code that is generated to create a line looks like this:
line = new QFrame(w);
line->setObjectName(QString::fromUtf8("line"));
line->setGeometry(QRect(320, 150, 118, 3));
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
Are
setGeometry
andsetFrameShadow
actually necessary? I'm still pretty new to Qt, but I would expect the style of frame shadow, by default, to depend on the overall Qt UI style. I'm trying to write cross-platform here.@MichaelScheper no the only calls necessary are
setFrameShape()
andsetFrameShadow()
.