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

来源:互联网 发布:软件设计规范怎么写 编辑:程序博客网 时间:2024/06/03 09:24

这是第二波控件


其中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_OBJECTpublic: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 0