Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [Solved] Display text and image in Tableview
Forum Updated to NodeBB v4.3 + New Features

[Solved] Display text and image in Tableview

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    th.thielemann
    wrote on last edited by
    #1

    I have a QAbstractTableModel and use QML's TableView to display it.

    • Roles are used to determine the column to display.
    • itemDelegate is used for the TableView cells

    Depending on the information in table, for some cells a icon has to display beside the text.
    What is a approach to transfer:

    a text from the data model

    a status value from the data model

    My first approaches were:

    • return value like: "Text:"text to display"Icon:TheImage.png" --> requires text parsing in qml file
    • overlay two TableViews: one for text, one for icons --> both icons's size and text size does not influence each other
      So I dismiss these.
    1 Reply Last reply
    0
    • T Offline
      T Offline
      th.thielemann
      wrote on last edited by
      #2

      Solution is to use a QMap containing the different values for text and icon.

      • in the datatype:

      @
      const QMap<QString,QVariant>& toMap()
      {
      QMap result;
      result.insert("text", m_text);
      ....
      return result;
      }
      @

      • In the model:

      @
      QVariant MyDataModel::data(const QModelIndex& index, int role) const
      {
      ...
      CellData myData; // Value for the current table cell
      return QVariant(myData.toMap());
      }
      @

      • in the qml

      @
      itemDelegate:
      Item {
      ...
      Text {
      ...
      text: styleData.value["text"]
      ...
      }
      Image {
      ...
      source: styleData.value["image"]
      ...
      }
      }
      @

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved