码迷,mamicode.com
首页 > 其他好文 > 详细

QT5-控件-QComboBox

时间:2016-02-21 21:18:35      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:

#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;

 

QT5-控件-QComboBox

标签:

原文地址:http://www.cnblogs.com/shiyumiao/p/5205566.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!