Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Display information on the fly
Qt 6.12 LTS is out! See what's new in the release blog

Display information on the fly

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 5 Posters 7.5k Views 2 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.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by
    #7

    Then follow @J-Hilk 's suggestion. it's executed basically in the same way as a table but you have just 1 column and the rest goes in different roles

    "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
    1
    • M Offline
      M Offline
      Mr Gisa
      wrote on last edited by
      #8

      I'm still confused about this, because the example he sent is about a delegate that is going to be in a column.
      I still don't know how I'm going to show a radio and tree label like in the image I sent.
      I would really appreciate an example.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mr Gisa
        wrote on last edited by
        #9

        Anyone to help me with an example about this?

        mrjjM 1 Reply Last reply
        0
        • M Mr Gisa

          Anyone to help me with an example about this?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #10

          @Mr-Gisa
          Hi you can disable the gridlines and change background and it it wont look cell like.
          The http://doc.qt.io/qt-5/qtwidgets-itemviews-stardelegate-example.html
          show a delegate example.
          In your case you would use QStyle to paint the radio button and use CreateEditor
          to create an action option button.
          You should read this for the model/view part
          http://doc.qt.io/qt-5/model-view-programming.html

          How many items are we talking about ?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mr Gisa
            wrote on last edited by
            #11

            A few, 10~15 max. Even less. I don't think it's going to be more than 15 tho.

            mrjjM 1 Reply Last reply
            0
            • M Mr Gisa

              A few, 10~15 max. Even less. I don't think it's going to be more than 15 tho.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #12

              @Mr-Gisa
              Ok luca will kill me for this but at such low number, you could use
              SetItemWidget which allows a widget to be placed on a "row"
              So you can use normal widgets and simply use a UI file in Designer
              and then create instances of this class and place on the rows.
              Note this is only good with few items and Desktop class pc.
              The performance is bad with many items and scrolling on mobile devices.
              The correct way is a Delegate. However its also a vbit involving.
              This is other example where it draws a progress bar via a Delegate.
              http://doc.qt.io/qt-5/qtnetwork-torrent-example.html
              It really is the best way , however, i must confess i used setItemWidget a few times
              as its so much easier and performance is not an issue in my use case. ;)

              VRoninV 1 Reply Last reply
              0
              • mrjjM mrjj

                @Mr-Gisa
                Ok luca will kill me for this but at such low number, you could use
                SetItemWidget which allows a widget to be placed on a "row"
                So you can use normal widgets and simply use a UI file in Designer
                and then create instances of this class and place on the rows.
                Note this is only good with few items and Desktop class pc.
                The performance is bad with many items and scrolling on mobile devices.
                The correct way is a Delegate. However its also a vbit involving.
                This is other example where it draws a progress bar via a Delegate.
                http://doc.qt.io/qt-5/qtnetwork-torrent-example.html
                It really is the best way , however, i must confess i used setItemWidget a few times
                as its so much easier and performance is not an issue in my use case. ;)

                VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #13

                @mrjj Tu quoque, Brute, fili mi!

                "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

                JonBJ mrjjM 2 Replies Last reply
                0
                • VRoninV VRonin

                  @mrjj Tu quoque, Brute, fili mi!

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #14

                  @VRonin That was too long. He only had time for: Et tu, Brute.

                  1 Reply Last reply
                  0
                  • VRoninV VRonin

                    @mrjj Tu quoque, Brute, fili mi!

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #15

                    @VRonin said in Display information on the fly:

                    Tu quoque, Brute, fili mi!

                    hehe yes. sorry. I guess back then his stepson Brutus didn't have any excuses but here
                    it might fit his use case as very few items. and no scrolling needed.

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

                      DEATH TO setItemWidget!

                      #include <QApplication>
                      #include <QStyledItemDelegate>
                      #include <QStandardItemModel>
                      #include <QSortFilterProxyModel>
                      #include <QTreeView>
                      #include <QHeaderView>
                      #include <QPushButton>
                      #include <QHBoxLayout>
                      #include <QVBoxLayout>
                      int main(int argc, char **argv) {
                          QApplication app(argc, argv);
                          QStandardItemModel model;
                          model.insertColumns(0,3);
                          model.insertRows(0,3);
                          for(int i=0;i<3;++i){
                             model.setData(model.index(i,0),QStringLiteral("autor"));
                             model.setData(model.index(i,1),QStringLiteral("resolution"));
                             model.setData(model.index(i,2),QStringLiteral("type"));
                             model.setData(model.index(i,0),Qt::Unchecked,Qt::CheckStateRole);
                             model.item(i,0)->setFlags(model.flags(model.index(i,0)) | Qt::ItemIsUserCheckable);
                          }
                          QWidget mainWid;
                          QTreeView* mainView = new QTreeView(&mainWid);
                          const QColor backColor = mainWid.palette().background().color();
                          mainView->setStyleSheet(QStringLiteral("QTreeView{border: 0px;background-color:%1;} QTreeView::item:hover{background-color:%1;}").arg(backColor.name(QColor::HexRgb)));
                          mainView->setModel(&model);
                          mainView->setIndentation(0);
                          mainView->setSelectionMode(QAbstractItemView::NoSelection);
                          mainView->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Preferred);
                          mainView->header()->setSectionResizeMode(QHeaderView::Stretch);
                          mainView->header()->hide();
                          mainView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
                          mainView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
                          QVBoxLayout* mainLay = new QVBoxLayout(&mainWid);
                          mainLay->addWidget(mainView);
                          QHBoxLayout* buttonLay=new QHBoxLayout;
                          buttonLay->addSpacerItem(new QSpacerItem(1,1,QSizePolicy::Expanding,QSizePolicy::Preferred));
                          buttonLay->addWidget(new QPushButton(QStringLiteral("select"),&mainWid));
                          mainLay->addLayout(buttonLay);
                      
                          //mutual exclusion.
                          QObject::connect(&model,&QAbstractItemModel::dataChanged,[&model](const QModelIndex& idx,const QModelIndex&,const QVector<int>& roles){
                              #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
                              if(!roles.contains(Qt::CheckStateRole)
                                 continue;
                              #endif
                              if(idx.column()==0 && idx.data(Qt::CheckStateRole)==Qt::Checked){
                                  for(int i=0, maxRow =model.rowCount() ;i<maxRow;++i){
                                      if(i==idx.row())
                                          continue;
                                      model.setData(model.index(i,0),Qt::Unchecked,Qt::CheckStateRole);
                                  }
                              }
                          });
                          mainWid.show();
                          return app.exec();
                      }
                      

                      "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

                      • Login

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