Qt学习五:控件二:下拉列表框、字体下拉列表框、QSpinBox控件、QScrollBar控件
2016-06-26 23:59
323 查看
这是第二波控件
其中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());
}
最后运行结果如下:
其中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());
}
最后运行结果如下:
相关文章推荐
- 一个qt的例子说明QWaitCondition的作用(条件变量)
- PyQt通过点击按钮选择文件并显示相对路径的例子
- Qt资料(一)
- Qt qss一些伪装态,以及margin与padding区别
- Qt双缓冲机制:实现一个简单的绘图工具(纯代码实现)
- 详细,Qt Creator快捷键大全,附快捷键配置方法
- Qt Creator 你必须要掌握的快捷操作
- Win7(32bit)下Qt5.5.0和OpenCV2.4.9环境的搭建
- QT mocing 系统找不到指定的路径
- windows下QT安装
- Qt Creator设置代码自动补全
- Qt5以上的建立空Qt项目时
- Qt学习四:控件一:按钮、标签、单行文本、多行文本
- 实现QT与HTML页面通信
- QT QWebKit使用心得(Qwebkit与Html之间通信)
- QT5 LNK2019 无法解析的外部符号
- qwt中常用的接口函数
- QT 信号处理
- qt 属性动态绑定
- Qt Creater中Clang-format的使用