实现一个简单的网格布局分布
1.新建一个无ui界面的工程,其基类为dialog
2.代码实现
dialog.h和main.cpp不做改变
dialog.cpp
#include
"dialog.h"
#include
<QLabel>
#include
<QGridLayout>
#include
<QPushButton>
#include
<QDial>
#include
<QSlider>
#include
<QLCDNumber>
Dialog
::Dialog(QWidget
*parent
)
: QDialog(parent
)
{
QPushButton
* m_quitpushbutton
= new QPushButton("退出",this);
QLabel
* m_cenlabel
= new QLabel("摄氏温度",this);
QLabel
* m_fahlabel
= new QLabel("华氏温度",this);
m_fahlabel
->setAlignment(Qt
::AlignCenter
);
QLabel
* m_label
= new QLabel("0",this);
QSlider
* m_slider
= new QSlider(this);
QLCDNumber
* m_lcdnumber
= new QLCDNumber(this);
QDial
* m_dial
= new QDial(this);
QGridLayout
* layout
= new QGridLayout(this);
layout
->setSpacing(10);
layout
->setMargin(20);
layout
->addWidget(m_quitpushbutton
,0,0,1,3);
layout
->addWidget(m_cenlabel
,1,0,1,2);
layout
->addWidget(m_fahlabel
,1,2);
layout
->addWidget(m_label
,2,0,2,1);
layout
->addWidget(m_slider
,2,1,2,1);
layout
->addWidget(m_lcdnumber
,2,2);
layout
->addWidget(m_dial
,3,2);
this->setLayout(layout
);
}
Dialog
::~Dialog()
{
}
3.效果展示
4.不足
1.这里没有将slider控件和label控件的信号与槽连接起来,因为没找到相应的槽函数,故无法拖动显示值 2.表盘控件dialog和lcd液晶显示没能实现信号连接
转载请注明原文地址: https://win8.8miu.com/read-2871.html