How does a designer create a line widget?

In Qt Designer, you can drag the Line widget, which will create a line in your layout.

But I checked the document and the headings, I did not find the title / widget "Line", what was it?

+9
source share
5 answers

In Qt 5.7, the code created by Qt Designer for a horizontal line (which can be checked in the menu using "Form / View Code ..."):

QFrame *line; line = new QFrame(Form); line->setFrameShape(QFrame::HLine); line->setFrameShadow(QFrame::Sunken); 

This will create the lines you see in Qt Designer.

The current answers do not seem to give working solutions, here is a comparison of all the answers (this solution is the first line):

Horizontal lines in Qt

Full code:

 #include <QtWidgets> int main(int argc, char **argv) { QApplication app(argc, argv); QWidget widget; auto layout = new QVBoxLayout; widget.setLayout(layout); widget.resize(200, 200); auto lineA = new QFrame; lineA->setFrameShape(QFrame::HLine); lineA->setFrameShadow(QFrame::Sunken); layout->addWidget(lineA); QWidget *lineB = new QWidget; lineB->setFixedHeight(2); lineB->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); lineB->setStyleSheet(QString("background-color: #c0c0c0;")); layout->addWidget(lineB); auto lineC = new QFrame; lineC->setFixedHeight(3); lineC->setFrameShadow(QFrame::Sunken); lineC->setLineWidth(1); layout->addWidget(lineC); QFrame* lineD = new QFrame; lineD->setFrameShape(QFrame::HLine); layout->addWidget(lineD); widget.show(); return app.exec(); } 
+9
source

I assume that you are referring to a horizontal / vertical line widget: this is just a simple QWidget with a gray background color, and horizontal is the correction height (1-3 pixels) and the expandable width widget, the vertical extension height of the widget.

Horizontal code example:

 QWidget *horizontalLineWidget = new QWidget; horizontalLineWidget->setFixedHeight(2); horizontalLineWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); horizontalLineWidget->setStyleSheet(QString("background-color: #c0c0c0;")); 
+7
source

This is a QFrame with a height of 3, a sunken shadow and a line width of 1. You can see this if you look at the header generated with the uic tool.

+4
source

Check out QFrame :: setFrameShape () . To get a string, use QFrame :: HLine or QFrame :: VLine as an argument to the function.

 // Create a horizontal line by creating a frame and setting its shape to QFrame::HLine: QFrame* hFrame = new QFrame; hFrame->setFrameShape(QFrame::HLine); // Create a vertical line by creating a frame and setting its shape to QFrame::VLine: QFrame* vFrame = new QFrame; vFrame->setFrameShape(QFrame::VLine); 
+3
source

Just add:

 addSeparator(); 

made.

0
source

Source: https://habr.com/ru/post/912647/


All Articles