Created
December 28, 2013 20:51
-
-
Save yamato8/8164070 to your computer and use it in GitHub Desktop.
Combo Box をソースコードから使う:Qt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mainwindow.h" | |
#include "ui_mainwindow.h" | |
#include <QComboBox> | |
#include <QDebug> | |
MainWindow::MainWindow(QWidget *parent) : | |
QMainWindow(parent), | |
ui(new Ui::MainWindow) | |
{ | |
ui->setupUi(this); | |
// コンボボックスがの追加 | |
QComboBox *my_comboBox = new QComboBox(this); | |
my_comboBox->addItem("1つ目のアイテム");// アイテムの追加 | |
my_comboBox->addItem("2つ目のアイテム");// アイテムの追加 | |
my_comboBox->addItem("3つ目のアイテム");// アイテムの追加 | |
my_comboBox->setGeometry(0,30,150,20);//位置の調整 | |
connect(my_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(handleSelectionChanged(int))); | |
} | |
MainWindow::~MainWindow() | |
{ | |
delete ui; | |
} | |
void MainWindow::handleSelectionChanged(int index) | |
{ | |
qDebug() << "アイテム:" << index << " が選択された"; // 0からカウント | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef MAINWINDOW_H | |
#define MAINWINDOW_H | |
#include <QMainWindow> | |
namespace Ui { | |
class MainWindow; | |
} | |
class MainWindow : public QMainWindow | |
{ | |
Q_OBJECT | |
public: | |
explicit MainWindow(QWidget *parent = 0); | |
~MainWindow(); | |
private slots: | |
void handleSelectionChanged(int index); | |
private: | |
Ui::MainWindow *ui; | |
}; | |
#endif // MAINWINDOW_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment