UID:156
UID:2
#include "dlg.h"int main(int argc, char **argv){ QApplication app(argc, argv); myDialog *dlg = new myDialog(); return dlg->exec();}
#ifndef _DLG_H_#define _DLG_H_#include <QtGui/QtGui>#include "ui_combobox.h"class myDialog:public QDialog{ Q_OBJECTpublic: myDialog(); ~myDialog();private slots: void buttonInsert(); void buttonDelete(); void comboBoxSelect(QString); void comboBoxSelect(int);private: Ui::Form *ui; };#endif //_DLG_H_
#include "dlg.h"myDialog::myDialog(){ ui = new Ui::Form(); ui->setupUi(this); connect(ui->PushButtonInsert, SIGNAL(clicked()), this, SLOT(buttonInsert())); connect(ui->PushButtonDelete, SIGNAL(clicked()), this, SLOT(buttonDelete())); connect(ui->ComboBoxTest, SIGNAL(activated(QString)), this, SLOT(comboBoxSelect(QString))); connect(ui->ComboBoxTest, SIGNAL(activated(int)), this, SLOT(comboBoxSelect(int)));}myDialog::~myDialog(){}void myDialog::buttonInsert(){ //QMessageBox::information(this, tr("Information"), tr("Alert"), QMessageBox::Ok); ui->ComboBoxTest->clear(); ui->ComboBoxTest->addItems(QStringList()<<"One"<<"Two"<<"Three"<<"Four"<<"Five");}void myDialog::buttonDelete(){ //QMessageBox::information(this, QString::number(ui->ComboBoxTest->currentIndex()), ui->ComboBoxTest->currentText(), QMessageBox::Ok); ui->ComboBoxTest->removeItem(ui->ComboBoxTest->currentIndex());}void myDialog::comboBoxSelect(QString strText){ setWindowTitle("You selected: " + strText);}void myDialog::comboBoxSelect(int iIndex){ setWindowTitle("You selected: " + ui->ComboBoxTest->itemText(iIndex));}
<ui version="4.0" > <author></author> <comment></comment> <exportmacro></exportmacro> <class>Form</class> <widget class="QWidget" name="Form" > <property name="geometry" > <rect> <x>0</x> <y>0</y> <width>387</width> <height>128</height> </rect> </property> <property name="windowTitle" > <string>Form</string> </property> <widget class="QPushButton" name="PushButtonInsert" > <property name="geometry" > <rect> <x>10</x> <y>90</y> <width>75</width> <height>23</height> </rect> </property> <property name="text" > <string>Insert</string> </property> </widget> <widget class="QPushButton" name="PushButtonDelete" > <property name="geometry" > <rect> <x>90</x> <y>90</y> <width>75</width> <height>23</height> </rect> </property> <property name="text" > <string>Delete</string> </property> </widget> <widget class="QPushButton" name="PushButtonClear" > <property name="geometry" > <rect> <x>170</x> <y>90</y> <width>75</width> <height>23</height> </rect> </property> <property name="text" > <string>Clear</string> </property> </widget> <widget class="QComboBox" name="ComboBoxTest" > <property name="geometry" > <rect> <x>20</x> <y>30</y> <width>351</width> <height>22</height> </rect> </property> </widget> <widget class="QPushButton" name="PushButtonQuit" > <property name="geometry" > <rect> <x>300</x> <y>90</y> <width>75</width> <height>23</height> </rect> </property> <property name="text" > <string>Quit</string> </property> </widget> </widget> <pixmapfunction></pixmapfunction> <resources/> <connections> <connection> <sender>PushButtonQuit</sender> <signal>clicked()</signal> <receiver>Form</receiver> <slot>close()</slot> <hints> <hint type="sourcelabel" > <x>320</x> <y>96</y> </hint> <hint type="destinationlabel" > <x>290</x> <y>73</y> </hint> </hints> </connection> <connection> <sender>PushButtonClear</sender> <signal>clicked()</signal> <receiver>ComboBoxTest</receiver> <slot>clear()</slot> <hints> <hint type="sourcelabel" > <x>207</x> <y>97</y> </hint> <hint type="destinationlabel" > <x>205</x> <y>37</y> </hint> </hints> </connection> </connections></ui>