Styles是QT自帶的例子 - 主要展示的是QT程序界面風格方面的編程知識
1.程序調(diào)色板的獲取
使用QApplication中的靜態(tài)函數(shù)
QApplication::palette
palette有2個版本一個是給定的調(diào)色板,另外一個給定的調(diào)色板
對應的調(diào)用
QApplication::setPalette
就可以設置新的程序調(diào)色板
如果使用自定義的Palette就可以達到修改界面色調(diào)的目的
比如:
2.QStyleFactory對象
The QStyleFactory class creates QStyle objects.可以通過靜態(tài)函數(shù)QStyleFactory::key()獲取工廠所支持的風格名字列表(注意是列表,返回類型是QStringList)
當然可以通過函數(shù)cerate來生成新的風格指針
3.QComboBox 組合框
主要函數(shù)有以下幾個:
通過函數(shù)addItem增加新項
通過addItems增加新項列表
通過插槽綁定就可以傳遞響應了:
connect(combobox,SIGNAL(activated(QString)),this, SLOT(changeComBox(QString)));
其他三個可能會用到的函數(shù)
currentIndex,count, currentText
4.QT計時器
拿例子說下:
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(advanceProgressBar()));
timer->start(1000);
首先構(gòu)造一個計時器 然后綁定計時器對象和槽函數(shù)
之后啟用計時器-每隔1秒鐘調(diào)用advaceProressBar函數(shù)
如果想停止計時器則調(diào)用stop函數(shù)即可
5.
QProgressBar進度條對象
基本的函數(shù)就那些
設置方向,當前值,最大值最小值,文本,可見性等等
progressBar = new QProgressBar;
progressBar->setRange(0, 10000);
progressBar->setValue(0);
其槽函數(shù)為
valueChanged ( int value )
6.單選按鈕QRodioButton
例子如下
topLeftGroupBox = new QGroupBox(tr("Group 1"));
radioButton1 = new QRadioButton(tr("Radio button 1"));
radioButton2 = new QRadioButton(topLeftGroupBox);
radioButton2->setText(tr("Radio button 2"));
radioButton3 = new QRadioButton(tr("Radio button 3"));
radioButton1->setChecked(true);
layout->addWidget(radioButton1);
layout->addWidget(radioButton2);
layout->addWidget(radioButton3);
似乎沒什么可說的
7.QTableWidget控件
The QTableWidget class provides an item-based table view with a default model.
需要說明的是如果要使用自定義類型,則需要使用QTableView而非QTableWidget.
tableWidget = new QTableWidget(this);
tableWidget->setRowCount(10);
tableWidget->setColumnCount(5);
不過感覺以后不會使用這個對象
8.QLineText
QT的單行輸入控件
具體函數(shù)有(似乎不需要說功能了)
QString text() const;
QString displayText() const;
int maxLength() const;
void setMaxLength(int);
bool isReadOnly() const;
void setReadOnly(bool);
bool isModified() const;
void setModified(bool);
9.
Q_INIT_RESOURCE(styles
);
加載資源文件
styles.qrc