qt - How to show icons use QSqlRelationalTableModel and QTableView in every row -
Now, I am trying to use QSqlRelationalTableModel and QTableView to show my data in the database, "fileType",
To show an icon in the first column, such as "Doc, Texty, XE, SLN" according to the suitability.
dirModel = new QSqlRelationalTableModel (this); DirModel-> Settable ("ecm_doc"); DirModel-> SetFilter (QString ("creatoruserid = '% 1' and parent = '% 2'"). Arg (userid) .arg (parentid); DirModel-> Selection (); DirView = New QTableView (this); DirView-> Set ITEM Deliaget (new diralit (this)); DirView-> SetModel (dirModel); DirView-> SetSelectionMode (QAbstractItemView :: SingleSelection); Show icon (); Zero DirTree :: showIcon () {int rowCount = dirModel- & gt; Punctiquity (); (For line row = 0; row & lt; rowCount; row ++) {// here is a test: i QModelIndex index = dimodel-> gt; Index (line, 1); QIcon Folder Icon (style () - & gt; Standard Pricessemap (QStyle :: SP_DirClosedIcon); DirModel-> Set data (index, folder icon, qt :: decorator); }} help me, wait online :)
You must have subclass from QSqlRelationalTableModel and replete the function to specify the icon: QVariant MyModel :: Data (Contemporary QMD Index and Index, Int role ) Const I believe that there is a DB table column with 1 file type property (index.column (== 1 and amp; role == QT :: decorative) {QSqlRecord r = model ray Ard (index.row ()); QString fileType = r.field (1) .value (). ToString (); Q icon icon; If (file type == "exe") icon = QIcon (": / PathToIcon / exe.png"); Else if (fileType == "sln") icon = QIcon (": / PathToIcon / sln.png"); ... back to QVariant (icon); } Return QSqlRelationalTableModel :: Data (index, role); }
Comments
Post a Comment