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. Custom QListView
Qt 6.11 is out! See what's new in the release blog

Custom QListView

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.2k 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.
  • M Offline
    M Offline
    maximus
    wrote on last edited by
    #1

    Hi,

    I would like to implement "this kind of interface":https://www.dropbox.com/s/rxy29mysyft2dfb/customListView.png:
    Each item in the list view would have 3 QString and 1 button that would emit a different signal (based on his device id)

    I am looking for the easiest and most robust way to do this in QT.
    I was thinking of a QListView instead of a QTableView because the information is better presented in a QListView. Is this kind of setup possible ? Is there some example that resemble this one? I haven't found much online. I have experience in QTableView but not much in QListView. I don't even know how to show 3 strings next to each other like on the picture using a QStandardItemModel item

    Thank you!

    code so far :
    @ model_hr = new QStandardItemModel(this);
    ui->listView_hr->setModel(model_hr);
    QStandardItem *item;
    item = new QStandardItem();
    item->setData( "Device", Qt::DisplayRole );
    item->setEditable( false );
    model_hr->appendRow( item );@


    Free Indoor Cycling Software - https://maximumtrainer.com

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

      Hi,

      You should have a look at the QStyledItemDelegate to start. There is e.g. the star delegate example in the documentation that shows how to make a completely custom delegate.

      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
      • M Offline
        M Offline
        maximus
        wrote on last edited by
        #3

        Hi SGaist thanks for your message,

        I understand the example but not sure it would be possible to have a button on each row with a different signal attached to it, I would have to have a slot that receive maybe int that represent the row in the model?
        @SLOT(clicked(int)) @
        so I know which one was clicked, or make the button name different when I add them to the grid but after in the slot i'm not sure I can retrieve the button name

        i.e:
        @connect(button_row1, SIGNAL(clicked(), this, SLOT(clicked())
        connect(button_row2, SIGNAL(clicked(), this, SLOT(clicked())

        void clicked() {
        if (event comes from row1)
        qDebug() << "row1"
        else if (event comes from row2)
        qDebug() << "row2"
        ...
        }@

        Merci


        Free Indoor Cycling Software - https://maximumtrainer.com

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

          You could use QSignalMapper

          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
          • M Offline
            M Offline
            maximus
            wrote on last edited by
            #5

            Thanks i'll experiment a bit and post the code when it's working ;)


            Free Indoor Cycling Software - https://maximumtrainer.com

            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