(1)因为老师讲的例题里用到了这个直线,再学习下 :
++
(2)由 QT 的 UIC 界面编译器生成的 c++ 代码,头文件 ui_widget.h 重的完整内容如下,其会讲解直线的生成:
#ifndef UI_WIDGET_H
#define UI_WIDGET_H
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QFrame>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_Widget
{
public:
QVBoxLayout * verticalLayout_3; //窗体的布局样式
QGroupBox * groupBox_2;
QVBoxLayout *verticalLayout;
QCheckBox * checkBox_2;
QFrame * line_2; //那条垂直线
QPushButton * pushButton_3;
QFrame * line; //那条水平线,居然是框架 QFrame
void setupUi(QWidget *Widget)
{
if (Widget->objectName().isEmpty())
Widget->setObjectName(QString::fromUtf8("Widget"));
Widget->resize(189, 154);
QFont font;
font.setPointSize(14);
Widget->setFont(font);
verticalLayout_3 = new QVBoxLayout(Widget); //窗体的总布局
verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3"));
groupBox_2 = new QGroupBox(Widget); //生成容器并采用垂直布局
groupBox_2->setObjectName(QString::fromUtf8("groupBox_2"));
verticalLayout = new QVBoxLayout(groupBox_2);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
checkBox_2 = new QCheckBox(groupBox_2); //添加第一个占位的复选框
checkBox_2->setObjectName(QString::fromUtf8("checkBox_2"));
verticalLayout->addWidget(checkBox_2);
line_2 = new QFrame(groupBox_2);
line_2->setObjectName(QString::fromUtf8("line_2"));
line_2->setFrameShadow(QFrame::Plain); //普通,这是框架的阴影的样式啊, shadow
line_2->setLineWidth(3);
line_2->setMidLineWidth(0);
line_2->setFrameShape(QFrame::VLine); //此渲染为垂直线
verticalLayout->addWidget(line_2); //把垂直线加入容器
pushButton_3 = new QPushButton(groupBox_2);
pushButton_3->setObjectName(QString::fromUtf8("pushButton_3"));
pushButton_3->setCheckable(false);
pushButton_3->setChecked(false);
pushButton_3->setAutoExclusive(false);
pushButton_3->setAutoDefault(false);
pushButton_3->setFlat(false);
verticalLayout->addWidget(pushButton_3);
line = new QFrame(groupBox_2);
line->setObjectName(QString::fromUtf8("line"));
line->setFrameShadow(QFrame::Raised); //阴影的效果是物体凸起的感觉
line->setLineWidth(3); //线宽也是 3
line->setFrameShape(QFrame::HLine); //显示为水平线
verticalLayout->addWidget(line);
verticalLayout_3->addWidget(groupBox_2); //容器也被加入了窗体
retranslateUi(Widget);
pushButton_3->setDefault(false);
QMetaObject::connectSlotsByName(Widget);
} // setupUi
void retranslateUi(QWidget *Widget)
{
Widget ->setWindowTitle(QCoreApplication::translate("Widget", "Widget2-1", nullptr));
groupBox_2 ->setTitle(QCoreApplication::translate("Widget", "GroupBox2" , nullptr));
checkBox_2 ->setText(QCoreApplication ::translate("Widget", "CheckBox" , nullptr));
pushButton_3->setText(QCoreApplication ::translate("Widget", "PushButton3", nullptr));
} // retranslateUi
};
namespace Ui {
class Widget: public Ui_Widget {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_WIDGET_H
(3) 上面例子里涉及的 QFrame 的源码支持,不全,精简版:
class Q_WIDGETS_EXPORT QFrame : public QWidget
{
Q_OBJECT //又插入了此宏
//取值如:Box Panel WinPanel HLine VLine。宏定义取值在本文件
//This property holds the frame shape value from the frame style
Q_PROPERTY(Shape frameShape READ frameShape WRITE setFrameShape )
Q_PROPERTY(Shadow frameShadow READ frameShadow WRITE setFrameShadow)
//This property holds the frame shadow value from the frame style
//取值为:Plain Raised Sunken沉没。 宏定义取值在本文件
//此属性保存行宽。 默认值为 1。
//请注意,用作分隔符的框架(HLine和VLine)的总行宽是由frameWidth指定的。
Q_PROPERTY(int lineWidth READ lineWidth WRITE setLineWidth)
Q_PROPERTY(int midLineWidth READ midLineWidth WRITE setMidLineWidth)
//This property holds the width of the mid-line
//The default value is 0.
public:
//WindowFlags = QFlags<WindowType> 描述本窗体是普通窗体还是对话框、弹出框等
explicit QFrame(QWidget * parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
//Constructs a frame widget with frame style NoFrame and a 1-pixel frame width.
//The parent and f arguments are passed to the QWidget constructor.
~QFrame();
enum Shape {
NoFrame = 0, // no frame
Box = 0x0001, // rectangular box
Panel = 0x0002, // rectangular panel
WinPanel = 0x0003, // rectangular panel (Windows)
HLine = 0x0004, // horizontal line
VLine = 0x0005, // vertical line
StyledPanel = 0x0006 // rectangular panel depending on the GUI style
};
Q_ENUM(Shape) //把本枚举类注册到元对象系统
enum Shadow {
Plain = 0x0010, // plain line
Raised = 0x0020, // raised shadow effect
Sunken = 0x0030 // sunken shadow effect
};
Q_ENUM(Shadow)
//Q_PROPERTY(Shape frameShape READ frameShape WRITE setFrameShape )
Shape frameShape() const;
void setFrameShape(Shape);
//Q_PROPERTY(Shadow frameShadow READ frameShadow WRITE setFrameShadow)
Shadow frameShadow() const;
void setFrameShadow(Shadow);
//Q_PROPERTY(int lineWidth READ lineWidth WRITE setLineWidth)
int lineWidth() const;
void setLineWidth(int);
//Q_PROPERTY(int midLineWidth READ midLineWidth WRITE setMidLineWidth)
int midLineWidth() const;
void setMidLineWidth(int);
//......................................略
}; //完结 class QFrame : public QWidget
(4)
谢谢