zoukankan      html  css  js  c++  java
  • QT项视图之QListWidget

    QT的项视图类有:QListWidget,QTableWidget,QTreeWidget

    QT的视图有:QListView,QTableView,QTreeView

    QT的模型有:QSqlTableModel,QStringListModel,QDirModel..等

    头文件:

    #ifndef XLISTWIDGET_H
    
    #define XLISTWIDGET_H
    
    #include <QtGui/QDialog>
    
    #include<QMap>
    
    class QDialogButtonBox;
    
    class QIcon;
    
    class QListWidget;
    
    class XListWidget : public QDialog
    
    {
    
        Q_OBJECT
    
    public:
    
        XListWidget(const QMap<int,QString>&symbolMap,QWidget *parent = 0);
    
        ~XListWidget();
    
    private:
    
        QIcon iconForSymbol(const QString &symbolName);
    
        QListWidget *listWidget;
    
        QDialogButtonBox *buttonBox;
    
    };
    
    #endif // XLISTWIDGET_H
    

    cpp文件:

    #include<QDebug>
    
    #include <QtGui>
    
    #include "xlistwidget.h"
    
    XListWidget::XListWidget(const QMap<int,QString>&symbolMap,
    
                             QWidget *parent)
    
        : QDialog(parent)
    
    {
    
        listWidget = new QListWidget;
    
        listWidget->setIconSize(QSize(60,60));
    
        QMapIterator<int,QString>i(symbolMap);
    
        while(i.hasNext()){
    
            i.next();
    
            QListWidgetItem *item = new QListWidgetItem(i.value(),listWidget);
    
            item->setIcon(iconForSymbol(i.value()));
    
            item->setData(Qt::UserRole,i.key());
    
        }
    
        QVBoxLayout *mainLayout = new QVBoxLayout;
    
        mainLayout->addWidget(listWidget);
    
        setLayout(mainLayout);
    
    }
    
    XListWidget::~XListWidget()
    
    {
    
    }
    
    QIcon XListWidget::iconForSymbol(const QString &symbolName)
    
    {
    
        QString fileName = ":/images/" + symbolName.toLower();
    
        qDebug()<<"fileName"<<fileName;
    
        fileName.replace(' ', '-');
    
        return QIcon(fileName);
    
    }

    main.cpp

    #include <QtGui/QApplication>
    
    #include "xlistwidget.h"
    
    int main(int argc, char *argv[])
    
    {
    
        QApplication a(argc, argv);
    
        QMap<int, QString> symbolMap;
    
        symbolMap.insert(132, QObject::tr("Data.png"));
    
        symbolMap.insert(134, QObject::tr("Decision.png"));
    
        symbolMap.insert(137, QObject::tr("Document.png"));
    
        symbolMap.insert(138, QObject::tr("Manual Input.png"));
    
        symbolMap.insert(139, QObject::tr("Manual Operation.png"));
    
        symbolMap.insert(141, QObject::tr("On Page Reference.png"));
    
        symbolMap.insert(142, QObject::tr("Predefined Process.png"));
    
        symbolMap.insert(145, QObject::tr("Preparation.png"));
    
        symbolMap.insert(150, QObject::tr("Printer.png"));
    
        symbolMap.insert(152, QObject::tr("Process.png"));
    
        XListWidget w(symbolMap);
    
        w.show();
    
        return a.exec();
    
    }
    
  • 相关阅读:
    layui table表格可搜索下拉框
    mysql重置密码
    纯js代码生成可搜索选择下拉列表
    ORACLE视图简单创建和使用
    zTree多条件模糊查询
    zTree模糊搜索,显示全部节点和高亮显示
    让我们来写一个v-model吧
    使用nodejs爬取静态网页数据
    vue-cli引用vant使用rem自适应
    前端以BASE64码的形式上传图片
  • 原文地址:https://www.cnblogs.com/xmphoenix/p/2135860.html
Copyright © 2011-2022 走看看