1.补充
对于一些控件的补充:
#include<QApplication>
//常用控件
#include<QLabel> //display static text or image
#include<QPushButton>
#include<QLineEdit> //single line
#include<QComboBox>//下拉框
#include<QCheckBox>//单选框
#include<QRadioButton>//圆点按钮(radio)
#include<QTextEdit> //multi lines,rich text
#include<QTextBrowser>//only read
#include<QGroupBox> //分类框
#include<QSlider> //(进度条)
#include<QSpinBox> //数字
//时间控件
#include<QTimeEdit>//时间表格
#include<QDateEdit>//日期表
#include<QDateTimeEdit>//时间日期
#include<QTabWidget>//不算控件
#include<QVBoxLayout>//
#include<QCompleter>//设置提示栏
#include<QHBoxLayout>
使用方法:
如果在多窗口的情况下,先设置一个主窗口(使用QVBoxLayout建立主窗口对象,然后在主窗口中使用lay->addWidget加入控件),最后直接对主窗口进行处理
MyWidget::MyWidget(QWidget *parent) : QWidget(parent)
{
QVBoxLayout*lay=new QVBoxLayout(this);
QLabel* label;
QComboBox* combo;
QPushButton* button1;
QRadioButton*rbutton1;
QTextEdit*edit;
QGroupBox*group;
QSlider*slider;
QSpinBox*spinBox;
//label支持HTML模式
lay->addWidget(label=new QLabel("<h1>lable</h1>"));//create a new widget
//label->setPixmap(QPixmap);构造图形
//Button 设置需要使用CSS风格
lay->addWidget(button1=new QPushButton("Button"));
button1->setStyleSheet("QPushButton{font:bold 16px;color:red}");//css style
//RadioButton
lay->addWidget(rbutton1=new QRadioButton("Radio"));
rbutton1->setStyleSheet("QRadioButton{font:bold 16px;color:blue}");//html格式设置
lay->addWidget(new QCheckBox("check box"));
lay->addWidget(combo=new QComboBox());//下拉框
combo->addItem("select item1");
combo->addItem("select item2");
combo->setEditable(true);//设置下拉框
combo->setCompleter(new QCompleter(QStringList()<<"new word1"<<"new word2"));
//html格式 爆炸了
lay->addWidget(edit=new QTextEdit);
edit->setText("<table border=1><tr><th>head1</th><th>head2</th></tr>"
"<tr><td>value1</td><td>value2</td></tr>"
"<tr><td>value3</td><td>value4</td></tr>"
"</table>");
lay->addWidget(group=new QGroupBox);
QHBoxLayout*hBoxLay;
group->setLayout(hBoxLay=new QHBoxLayout);
hBoxLay->addWidget(new QLabel("widget1"));
hBoxLay->addWidget(new QLabel("widget2"));
lay->addWidget(slider=new QSlider(Qt::Horizontal));
//
slider->setMaximum(100);
slider->setMinimum(0);
lay->addWidget(spinBox=new QSpinBox);
//spinBox和Slider的控件类似 区别在于显示的方法不同
spinBox->setMaximum(100);
spinBox->setMinimum(0);
lay->addWidget(new QDateTimeEdit);
}
//basic frame
int main(int argc,char**argv)
{
QApplication app(argc,argv);
//建立主窗口
MyWidget w;
w.show();
return app.exec();
}
注:对于每一个控件先建立相应的对象
QLabel* label;
lay->addWidget(label=new QLabel("<h1>lable</h1>"));//create a new widget
然后对于相应的对象进行处理
lable-> //使用相应函数,自定义控件
注:
由于一个成熟的软件需要很多控件之间相互使用,在注意控件空间位置的同时 注意代码的规范性,区域化代码的使用
引用和对象的创建一般在头文件中使用