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 QTableView

Custom QTableView

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

    Hi!
    Are there any ways to get such a QTableView? I need independent sub-tables ("independent" in sense of separate indexing and adding new rows from separate models), but these sub-tables must share common columns
    QTableViews

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

      Hi,

      Do you mean you would have something like 3 different QTableView glued to each other in order to show the information you want ?

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

      T 1 Reply Last reply
      3
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        Do you mean something like this? https://api.kde.org/frameworks/kitemmodels/html/classKConcatenateRowsProxyModel.html

        "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

        T 1 Reply Last reply
        2
        • SGaistS SGaist

          Hi,

          Do you mean you would have something like 3 different QTableView glued to each other in order to show the information you want ?

          T Offline
          T Offline
          Tikani
          wrote on last edited by
          #4

          @SGaist
          Yes, something like that. These QTableViews must have the same columns but the horizontal rows (without cells) with titles are mandatory. And it could be a totally different number of rows in the each 'glued' QTableViews. I can't even imagine how to implement it.

          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by VRonin
            #5
            • create the 3 table models
            • create 2 table models with the same number of columns but just 1 row, fill element 0,0 of these models with the title
            • use KConcatenateRowsProxyModel and add the 5 models in the order they should appear
            • use QTableView::setSpan to make the the headers span multiple columns

            Alternatively:

            • create 3 QTableView, one for each model
            • set their size policy as QSizePolicy::Minimum and disable the scrollbars
            • lay them out in QWidget with a QVBoxLayout with no margins or borders
            • add the widget to a QScrollArea

            "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
            • VRoninV VRonin

              Do you mean something like this? https://api.kde.org/frameworks/kitemmodels/html/classKConcatenateRowsProxyModel.html

              T Offline
              T Offline
              Tikani
              wrote on last edited by Tikani
              #6

              @VRonin
              Maybe :) but i don't know how to insert sub-titles to its places like in the picture above. This complex table is a reflection of badly structured paper utility bill and the customer wants total correspondence. :(

              VRoninV 1 Reply Last reply
              0
              • T Tikani

                @VRonin
                Maybe :) but i don't know how to insert sub-titles to its places like in the picture above. This complex table is a reflection of badly structured paper utility bill and the customer wants total correspondence. :(

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

                @Tikani said in Custom QTableView:

                how to insert sub-titles

                QAbstractItemModel* model = new QStandardItemModel(this);
                model->insertCoulmns(0,4);
                model->insertRows(0,5);
                model->setData(model->index(0,0),QStringLiteral("Subtitle"));
                for(int j=1;j<5;++j){
                for(int i=0;i<4;++i){
                model->setData(model->index(j,i),QString::number(j) + ','+QString::number(i)); 
                }}
                QTableView* view=new QTableView(this);
                view->setModel(model);
                view->setSpan(0,0,1,4);
                view->horizontalHeader()->hide();
                view->verticalHeader()->hide();
                

                "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