设计人员如何创建Line小部件? [英] How does designer create a Line widget?
问题描述
在Qt Designer中,您可以拖动线"小部件,这将在您的布局中创建线.
In Qt Designer , you can drag a "Line" widget , which will create a line in your layout.
但是我检查了文档和标题,但是找不到"Line"标题/小部件,这是什么?
But I checked the document and headers , I didn't find the "Line" header / widget , what was it ?
推荐答案
在Qt 5.7中,由Qt Designer生成的用于水平线的代码(可以在菜单中使用表单/查看代码..."进行检查) :
In Qt 5.7 the code generated by Qt Designer for a Horizontal Line (which can be checked in the menu using "Form/View Code...") is:
QFrame *line;
line = new QFrame(Form);
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
这将创建您在Qt Designer中看到的行.
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 answers (this solution is the first line):
完整代码:
#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();
}
这篇关于设计人员如何创建Line小部件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!