Qt学习五:控件二:下拉列表框、字体下拉列表框、QSpinBox控件、QScrollBar控件

这是第二波控件


其中qtButton.h中的程序是

#ifndef QTBUTTON_H
#define QTBUTTON_H

#include <QtWidgets/QMainWindow>
#include "ui_qtbutton.h"

//-------------------------------
#include<qcombobox.h>

#include<qfontcombobox.h>
#include<qpushbutton.h>
#include<qlabel.h>

#include<qspinbox.h>

#include<qscrollbar.h>
#include<qspinbox.h>

//---------------------------


class qtButton : public QMainWindow
{
	Q_OBJECT

public:
	qtButton(QWidget *parent = 0);
	~qtButton();

private:
	Ui::qtButtonClass ui;
	QComboBox *comboBox;

	QFontComboBox *fontComboBox;
	QPushButton *button;
	QLabel *label;

	QSpinBox *spinBox;

	QScrollBar *scrollBar; //滚动条
	QSpinBox *spinBox1;

	private slots:
	void txtButton();

};

#endif // QTBUTTON_H



另外,qtButton.cpp里面的程序如下:

#include "qtbutton.h"


qtButton::qtButton(QWidget *parent)
: QMainWindow(parent)
{
	ui.setupUi(this);
	//------------------ComboBox------
	comboBox = new QComboBox(this);
	comboBox->setGeometry(QRect(50, 50, 120, 25));
	QStringList str;
	str << "Methamatic" << "Chinese" << "Geometry";
	comboBox->addItems(str);
	//----------------------------------

	//----------------QFontComboBox------------
	fontComboBox = new QFontComboBox(this);
	button = new QPushButton(this);
	label = new QLabel(this);


	label->setGeometry(QRect(50, 150, 300, 25));
	button->setText("button");
	button->move(180, 100);//注意button控件的运行方式

	connect(button, SIGNAL(released()), this, SLOT(txtButton()));

	fontComboBox->setGeometry(QRect(50, 100, 120, 25));
	//----------------------------------------

	//-------------QSpinBox-------------------
	spinBox = new QSpinBox(this);
	spinBox->setGeometry(QRect(50, 150, 100, 25));

	spinBox->setRange(0, 200);
	spinBox->setValue(10);
	spinBox->setSuffix("Yan");
	spinBox->setPrefix("$");

	//----------------------------------------------------

	//---------ScrollBar---------------------
	scrollBar = new QScrollBar(this);
	scrollBar->setOrientation(Qt::Horizontal);
	scrollBar->setGeometry(QRect(50, 200, 180, 20));
	scrollBar->setPageStep(10);
	scrollBar->setValue(50);



	spinBox1 = new QSpinBox(this);
	spinBox1->setGeometry(QRect(50, 250, 100, 25));

	//必须把connect放在最下面;
	connect(scrollBar, SIGNAL(valueChanged(int)), spinBox1, SLOT(setValue(int)));
	connect(spinBox1, SIGNAL(valueChanged(int)), scrollBar, SLOT(setValue(int)));




	//---------------------------------------------
}

qtButton::~qtButton()
{

}

void qtButton::txtButton()
{
	label->setText("choose font:" + fontComboBox->currentText());
}

最后运行结果如下:


  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值