Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. List of Items with texts and icons. QAbstractItemModel?
Forum Updated to NodeBB v4.3 + New Features

List of Items with texts and icons. QAbstractItemModel?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.3k 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.
  • dediggefeddeD Offline
    dediggefeddeD Offline
    dediggefedde
    wrote on last edited by
    #1

    Hi!
    I'm pretty new to QT, so there might be some misunderstandings in concepts.
    What I would like to display is a list (ListView) of Items of which each displays multiple texts and icons.

    I can successfully display single text elements with QStandardItemModel and I read about subclassing QAbstractItemModel if you need to display things differently. In QT help I also found an example for having a list of images (puzzle), but I couldn't find a combination or an example how to set the positions of multiple text elements.

    In the past in vc++ or bcc I usually used the graphical base class (for labels etc.), subclassed it and changed the paint and mouse[...] events until it looked like I want.

    To display a list of items that show multiple text and icons, would it be better to subclass QAbstractItemModel and put it into a Listview or to create my own "Listview" as a QFrame subclass?

    best Regards
    Dediggefedde

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      The model does not determine how things are displayed, it just contains the data.

      The view determines how the data as a whole is displayed (tree, list, table, etc.)

      The delegate determines how individual items in the view are displayed.

      check http://doc.qt.io/qt-5/model-view-programming.html for more detail

      From your description it looks like what you need to subclass QStyledItemDelegate. What you need to do is store your text and icons in different Data Roles from Qt::UserRole onward and use the delegate paint method to retrieve them and display them.

      The star delegate example is a good place to start

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      2
      • dediggefeddeD Offline
        dediggefeddeD Offline
        dediggefedde
        wrote on last edited by dediggefedde
        #3

        @VRonin :
        Thanks for the fast and helpful reply!
        I took a look into the model/view explanation and the star delegate example.

        Edit: Sorry, I forgot to set the data to 0 on the QListView.
        For QListView setItem parameters are (data,role), for QTableWidget it's (role,data)

        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