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. QListWidget and items with several informations
Forum Updated to NodeBB v4.3 + New Features

QListWidget and items with several informations

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.5k 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.
  • E Offline
    E Offline
    enforcer
    wrote on last edited by
    #1

    Hello community!

    I'm programming a software for an American Football team where they can manage their formations and plays. It draws everything with QPainter into a self-programmed render widget and it can use it to create PNGs, JPEGs etc.

    For a good looking UI I heard of QListWidget and QListWidgetItem to show a list of the saved formations and plays. The icons you can add in QListWidgetItem are useful to show a little picture of the play so that you know immediately what play it is. The list itself only shows small picture and formation/play's name.

    The problem:
    According to "QListWidgetItem Reference":http://qt-project.org/doc/qt-5.0/qtwidgets /qlistwidgetitem.html#setData you can only store one information which is a QVariant. But as informations I need the following:

    • Players (Positions in x and y and if Player is QB, RB, LB etc.)
    • Players' routes
    • Formation/Play's name
    • Formation/Play's notes
    • Play style (offense, defense, special)
    • Picture of formation/play (rendered with QPainter)

    When I double-click the item or single-click it and press a button the play should be displayed in my render-widget which also contains the above informations.

    Is there a way to save all these informations in QListWidgetItem? I'd like to avoid synchronizing QStringList in QListWidget and QList<Formation*>

    lg enforcer

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Put all these information in a class or structure and then put that in the item's data

      @item->setData(QVariant::fromValue(yourFormatData))@

      Have a look at the "QVariant":http://qt-project.org/doc/qt-4.8/qvariant.html#details doc as well as the QMetaType

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • E Offline
        E Offline
        enforcer
        wrote on last edited by
        #3

        I'm not that familiar with QMetaType. I remember one project in Java where I updated a ListWidget each time a Vector<...> changed content (add object, delete object, update informations of object). I hoped to have it easier in Qt, but I think this is the most convenient way for me.

        But thanks for your advise.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then you could use a QListView with a custom model. Change the data in the model and the view will be updated for you accordingly.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • E Offline
            E Offline
            enforcer
            wrote on last edited by
            #5

            How about an own class derived from QListWidgetItem. It inherits a pointer to my class where all needed infos are saved. It also consists of a slot connected with QListWidget::itemActivated(QListWidgetItem*) signal. If signal argument == this, then load info_pointer into my render-widget.
            In constructor I call setData(...) and setIcon(...).

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              That's another solution, it's up to you to validate what's the best for you :)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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