「Qtのコントロール - コンボボックス」の版間の差分
ナビゲーションに移動
検索に移動
(→概要) |
細 (文字列「__FORCETOC__」を「{{#seo: |title={{PAGENAME}} : Exploring Electronics and SUSE Linux | MochiuWiki |keywords=MochiuWiki,Mochiu,Wiki,Mochiu Wiki,Electric Circuit,Electric,pcb,Mathematics,AVR,TI,STMicro,AVR,ATmega,MSP430,STM,Arduino,Xilinx,FPGA,Verilog,HDL,PinePhone,Pine Phone,Raspberry,Raspberry Pi,C,C++,C#,Qt,Qml,MFC,Shell,Bash,Zsh,Fish,SUSE,SLE,Suse Enterprise,Suse Linux,openSUSE,open SUSE,Leap,Linux,uCLnux,Podman,電気回路,電子回路,基板,プリント基板 |description={{PAGENAME}} - 電子回路とSUSE Linuxに関する情報 | This pag…) |
||
| 73行目: | 73行目: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br><br> | <br><br> | ||
{{#seo: | |||
|title={{PAGENAME}} : Exploring Electronics and SUSE Linux | MochiuWiki | |||
|keywords=MochiuWiki,Mochiu,Wiki,Mochiu Wiki,Electric Circuit,Electric,pcb,Mathematics,AVR,TI,STMicro,AVR,ATmega,MSP430,STM,Arduino,Xilinx,FPGA,Verilog,HDL,PinePhone,Pine Phone,Raspberry,Raspberry Pi,C,C++,C#,Qt,Qml,MFC,Shell,Bash,Zsh,Fish,SUSE,SLE,Suse Enterprise,Suse Linux,openSUSE,open SUSE,Leap,Linux,uCLnux,Podman,電気回路,電子回路,基板,プリント基板 | |||
|description={{PAGENAME}} - 電子回路とSUSE Linuxに関する情報 | This page is {{PAGENAME}} in our wiki about electronic circuits and SUSE Linux | |||
|image=/resources/assets/MochiuLogo_Single_Blue.png | |||
}} | |||
__FORCETOC__ | __FORCETOC__ | ||
[[カテゴリ:Qt]] | [[カテゴリ:Qt]] | ||
2024年10月14日 (月) 10:57時点における版
概要
Qtにおいて、QComboBoxクラスを使用してコンボボックスをコントロールする手順を記載する。
サンプルコード
以下に、QComboBoxクラスを使用したサンプルコードを示す。
uiファイルにおいて、コンボボックスコントロールとボタンコントロールを配置する。
ボタンコントロールのシグナルはclicked()、スロットはOnBtnClicked()を選択する。
コンボボックスコントロールの1つ目のアイテムを選択した場合、メッセージボックスに0を表示する。
また、2つ目のアイテムの場合は1、3つ目のアイテムの場合は2を表示する。
// mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->comboBox->addItem("Fox1");
ui->comboBox->addItem("Fox2");
ui->comboBox->addItem("Fox3");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::OnBtnClicked()
{
// This property holds the index of the current item in the combobox.
QString strIndex = QString::number(ui->comboBox->currentIndex());
QMessageBox::information(this, "title", strIndex);
}
以下の例では、ComboBoxコントロールにおいて、指定した要素にアイテムを挿入している。
// mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->comboBox->addItem("Fox1");
ui->comboBox->addItem("Fox2");
ui->comboBox->addItem("Fox3");
ui->comboBox->insertItem(1, "homing missile");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::OnBtnClicked()
{
// This property holds the index of the current item in the combobox
QString strIndex = QString::number(ui->comboBox->currentIndex());
QMessageBox::information(this, "title", strIndex);
}