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. Display information on the fly
Forum Updated to NodeBB v4.3 + New Features

Display information on the fly

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 5 Posters 2.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.
  • M Offline
    M Offline
    Mr Gisa
    wrote on last edited by
    #3

    Hi, thank you for your answer. You might be right, but I have no idea how to do something like that. Let's see if someone helps me with that.

    J.HilkJ 1 Reply Last reply
    0
    • M Mr Gisa

      Hi, thank you for your answer. You might be right, but I have no idea how to do something like that. Let's see if someone helps me with that.

      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #4

      @Mr-Gisa
      well I can point you to the right docu section at least :-)

      There's the Stardelegate Example that is actually pretty close to your current situation.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #5
        • create a QStandardItemModel
        • call QStandardItemModel::insertColumns(0,3)
        • Iterate over the results using QJsonArray
        • call QStandardItemModel::insertRow + QStandardItemModel::setData to populate the model (you can save the link in Qt::UserRole)
        • create a QTableView and call setModel on it to assign your model

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

          @VRonin The approach you said is using a table, I don't want it to be like a table (in appearance). It would look something like this:

          0_1531133455784_939b249c-159b-4719-9780-a7f9e541517d-image.png

          1 Reply Last reply
          0
          • 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 Extensions
                              • Unsolved