QT5-控件-QComboBox

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QComboBox>

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

    QComboBox* combo ;

public slots:
    void valueChanged();
};

#endif // MAINWINDOW_H
#include "mainwindow.h"
#include <QtDebug>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    this->resize(400,300);
    this->centralWidget();
    combo = new QComboBox(this);
    combo->setGeometry(100,100,200,30);

    combo->addItem(QIcon("res/01.png"),"程序");
    combo->addItem(QIcon("res/02.png"),"图形");
    combo->addItem(QIcon("res/03.png"),"数据");
    combo->addItem(QIcon("res/04.png"),"网络");

    connect(combo,SIGNAL(currentIndexChanged(int)),this,SLOT(valueChanged()));

}

MainWindow::~MainWindow()
{

}

void MainWindow::valueChanged()
{
    int currentIndex = combo->currentIndex();
    QString currentText = combo->currentText();
    qDebug()<<currentIndex<<currentText;
}
#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

 

If you include <QtDebug>,

a more convenient syntax is also available:

qWarning() << "Brush:" << myQBrush << "Other value:"<< i;

 

转载于:https://www.cnblogs.com/shiyumiao/p/5205566.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值