您的位置:首页 > 编程语言 > Qt开发

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

2016-06-26 23:59 323 查看
这是第二波控件

其中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());
}
最后运行结果如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: