QT的项视图类有:QListWidget,QTableWidget,QTreeWidget
QT的视图有:QListView,QTableView,QTreeView
QT的模型有:QSqlTableModel,QStringListModel,QDirModel..等
头文件:
#ifndef XLISTWIDGET_H#define XLISTWIDGET_H#include#includeclass QDialogButtonBox;class QIcon;class QListWidget;class XListWidget : public QDialog{Q_OBJECTpublic:XListWidget(const QMap&symbolMap,QWidget *parent = 0); ~XListWidget();private:QIcon iconForSymbol(const QString &symbolName);QListWidget *listWidget;QDialogButtonBox *buttonBox;};#endif // XLISTWIDGET_H
cpp文件:
#include
#include
#include "xlistwidget.h"
XListWidget::XListWidget(const QMap&symbolMap,
QWidget *parent)
: QDialog(parent)
{
listWidget = new QListWidget;
listWidget->setIconSize(QSize(60,60));
QMapIteratori(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.replace(' ', '-');
return QIcon(fileName);
}
main.cpp
#include
#include "xlistwidget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMapsymbolMap;
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();
}