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. QTableView Fixing Some Columns
Forum Updated to NodeBB v4.3 + New Features

QTableView Fixing Some Columns

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 931 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.
  • JonBJ JonB

    @DzCode
    One possibility would be to introduce a QAbstractProxyModel on top of your model as the source for one of the table views. Start from QIdentityProxyModel, and just change the drag/drops allowed. Now attach one view to the original model and the other to the proxy model.

    D Offline
    D Offline
    DzCode
    wrote on last edited by DzCode
    #3

    @JonB They have to use the same custom model, they have some shared properties and each time one table is updated, allso other one updated.

    But my original question is also about one table. I want to make some columns movable, some not in the view and not affaectin the other table

    JonBJ 1 Reply Last reply
    0
    • D DzCode

      @JonB They have to use the same custom model, they have some shared properties and each time one table is updated, allso other one updated.

      But my original question is also about one table. I want to make some columns movable, some not in the view and not affaectin the other table

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

      @DzCode
      I don't understand.

      I thought you had one table, two views.

      If you have separate table models, one of which is to allow more dragging than the other, then make the models return different values for what can be dragged.

      D 1 Reply Last reply
      0
      • JonBJ JonB

        @DzCode
        I don't understand.

        I thought you had one table, two views.

        If you have separate table models, one of which is to allow more dragging than the other, then make the models return different values for what can be dragged.

        D Offline
        D Offline
        DzCode
        wrote on last edited by
        #5

        @JonB I have two different TableView with the same model

        JonBJ 1 Reply Last reply
        0
        • D DzCode

          @JonB I have two different TableView with the same model

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

          @DzCode
          Then I do not understand your:

          and each time one table is updated, allso other one updated.

          since there is only one model to update.

          D 1 Reply Last reply
          0
          • JonBJ JonB

            @DzCode
            Then I do not understand your:

            and each time one table is updated, allso other one updated.

            since there is only one model to update.

            D Offline
            D Offline
            DzCode
            wrote on last edited by
            #7

            @JonB

            The thing I want is below:

            Think that there is only one table
            The first 3 columns are fixed in the table. (A,B,C)

            Other column headers are: D,E,G.

            D,E,G column headers should be movable between themselves. However, they should not be dragged and droped to the A,B,C columns region in the table.
            I only want to move D,E,G between column order 4 and 6. not dragged to first 3 columns' place.

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

              Hi,

              You will need a custom header view or a filter that ignores the mouse move event on these columns and possible the mouse press as well.

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

              D 2 Replies Last reply
              1
              • SGaistS SGaist

                Hi,

                You will need a custom header view or a filter that ignores the mouse move event on these columns and possible the mouse press as well.

                D Offline
                D Offline
                DzCode
                wrote on last edited by
                #9

                @SGaist Hi SGaist,

                How can I handle in mousemoveevent. inside my tableview, I am trying to get the modelindex from the mouse position and checking for column. But it does not work.

                1 Reply Last reply
                0
                • SGaistS SGaist

                  Hi,

                  You will need a custom header view or a filter that ignores the mouse move event on these columns and possible the mouse press as well.

                  D Offline
                  D Offline
                  DzCode
                  wrote on last edited by
                  #10

                  @SGaist

                  I implemented a new QHeaderView and in mousereleaseevent:

                  void CustomHeaderView::mouseReleaseEvent(QMouseEvent *event)
                  {
                      if (event->pos().x() > sectionViewportPosition(2) && event->pos().x() < sectionViewportPosition(3))
                      {
                          return;
                      }
                  
                      QHeaderView::mouseReleaseEvent(event);
                  }
                  

                  This actually solves my problem with a bug. This ignores the event when I want to release mouse over the 2nd column header.
                  Problem 1:
                  2020-09-14 13_06_39-TestApp.png
                  Problem 2:
                  This ruins my sortable columns. When I want to sort the table according to 2nd column, because fo the return from mouserelease I cannot sort the table.

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

                    Did you try to just ignore the mouseMoveEvent on these columns rather than release ?

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

                    D 1 Reply Last reply
                    1
                    • SGaistS SGaist

                      Did you try to just ignore the mouseMoveEvent on these columns rather than release ?

                      D Offline
                      D Offline
                      DzCode
                      wrote on last edited by
                      #12

                      @SGaist thanks. it solves the problem

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

                        Great !

                        Since you have it working now, please mark the thread as solved using the "Topic Tools" button or the three dotted menu beside the answer you deem correct so that other forum users may know a solution has been found :-)

                        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