zoukankan      html  css  js  c++  java
  • 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;

  • 相关阅读:
    mobx的一个记录
    前端模块规范AMD/UMD/CommonJs
    CSS3字体大小单位的认识px/em/rem
    各浏览器之间的字号检测
    react整理一二(初入React世界)
    Node.js中实现套接字服务
    闲来无事,把node又拾起来看看
    判断类型
    html5 搜索框
    CSS 设置placeholder属性
  • 原文地址:https://www.cnblogs.com/shiyumiao/p/5205566.html
Copyright © 2011-2022 走看看