Qt5 常用控件的熟悉

Qt5.9+VS2017

效果图:

Qt5 常用控件的熟悉_第1张图片

部分代码:

#include "QtGuiApplication1.h"

#include      // disply static text, or image
#include 
#include  // single line

#include 
#include 
#include 
#include  // multi lines, rich text
#include  // readonly textedit
#include   //
#include     // 模拟方式显示数值
#include   // 数字
#include 
#include 
#include 
#include  // 不介绍,不算控件
#include 
#include 
#include 
#include 
#include  


QtGuiApplication1::QtGuiApplication1(QWidget *parent)
	: QWidget(parent)
{
	QVBoxLayout *lay = new QVBoxLayout(this);
	QLabel *label = new QLabel("baidu");
	QPushButton *button = new QPushButton("Button");
	QRadioButton *radio = new QRadioButton("Radio");
	QCheckBox *check = new QCheckBox("check box");
	QComboBox *combo = new QComboBox();
	QTextEdit *edit = new QTextEdit();
	QGroupBox *groupbox = new QGroupBox("some items");

	lay->addWidget(label);

	connect(label, &QLabel::linkActivated, [](QString str) {
	
		qDebug() << str;
	});
	lay->addWidget(button);
	lay->addWidget(radio);
	connect(radio, &QRadioButton::clicked, [](bool val) {
		qDebug() << val;
	
	});
	lay->addWidget(check);
	connect(check, &QCheckBox::clicked, [](bool val) {
		qDebug() << val;
	});
	lay->addWidget(combo);
	combo->addItem("Select item1");
	combo->addItem("Select item2");
	combo->setEditable(true);
	
	lay->addWidget(edit);
	//垂直滚动条
	edit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
	//水平滚动条
	edit->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);


	lay->addWidget(groupbox);


	QHBoxLayout *hBoxlay = new QHBoxLayout();

	groupbox->setLayout(hBoxlay);
	hBoxlay->addWidget(new QPushButton("aaa"));
	hBoxlay->addWidget(new QPushButton("bbb"));
	
	QSlider *slider;
	QSpinBox *spinbox;

	lay->addWidget(slider = new QSlider(Qt::Horizontal));
	slider->setMaximum(100);
	slider->setMinimum(0);
	//connect(slider, &QSlider::valueChanged, [](int val) {
	//	qDebug() << val;
	//});
	lay->addWidget(spinbox = new QSpinBox);
	spinbox->setMaximum(100);
	spinbox->setMinimum(0);

	connect(slider, &QSlider::valueChanged, spinbox, &QSpinBox::setValue);

	//信号函数有重载,使用函数指针
	//connect(spinbox, &QSpinBox::valueChanged, slider, &QSlider::setValue);
	//void (QSpinBox:: *valueChanged_int)(int) = &QSpinBox::valueChanged;
	//connect(spinbox, valueChanged_int, slider, &QSlider::setValue);
	connect(spinbox, 
		static_cast (&QSpinBox::valueChanged),
		slider,
		&QSlider::setValue);
}

 

你可能感兴趣的:(Qt)