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. drag-and-drop columns.
Forum Updated to NodeBB v4.3 + New Features

drag-and-drop columns.

Scheduled Pinned Locked Moved Unsolved General and Desktop
21 Posts 5 Posters 2.3k 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.
  • N Offline
    N Offline
    Nevez
    wrote on 25 Aug 2022, 05:28 last edited by
    #3

    Thank you.
    I checked the source you suggested and now I can drag and drop the labels in those titles.
    However, my labels are now completely independent with the tableview.
    How can I update the columns in the table in line with the operations with labels?

    J 1 Reply Last reply 25 Aug 2022, 06:33
    0
    • N Nevez
      25 Aug 2022, 05:28

      Thank you.
      I checked the source you suggested and now I can drag and drop the labels in those titles.
      However, my labels are now completely independent with the tableview.
      How can I update the columns in the table in line with the operations with labels?

      J Offline
      J Offline
      JonB
      wrote on 25 Aug 2022, 06:33 last edited by JonB
      #4

      @Nevez
      I assume you are using a model as the backing store for the table. Does whatever class you are using for your model implement QAbstractItemModel::insertColumns() and is it called on label drop, I presume you will need that?

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Nevez
        wrote on 26 Aug 2022, 05:52 last edited by
        #5

        link
        Frankly, in the link here, they say that the insertcolumns method is not very useful for updating the model.
        Do you think I should use QSortFilterProxyModel?

        J 1 Reply Last reply 26 Aug 2022, 08:04
        0
        • N Nevez
          26 Aug 2022, 05:52

          link
          Frankly, in the link here, they say that the insertcolumns method is not very useful for updating the model.
          Do you think I should use QSortFilterProxyModel?

          J Offline
          J Offline
          JonB
          wrote on 26 Aug 2022, 08:04 last edited by
          #6

          @Nevez
          That link is speaking about a SQL database as the backing model. You have said nothing about what you are using. A QSortFilterProxyModel won't help, I don't know why they mentioned that. A subclassing of QIdentityProxyModel may be wanted, but cannot say until you state what you will using as your backing model and how you intend adding/removing columns to behave.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            Nevez
            wrote on 26 Aug 2022, 12:02 last edited by
            #7

            Basically what I want to do is:
            Creating a model over the Mysql database, adding and removing columns in this model, and updating the View again according to this model.

            but, of course, to add/remove columns according to the added/removed index of the labels above

            J 1 Reply Last reply 26 Aug 2022, 12:11
            0
            • N Nevez
              26 Aug 2022, 12:02

              Basically what I want to do is:
              Creating a model over the Mysql database, adding and removing columns in this model, and updating the View again according to this model.

              but, of course, to add/remove columns according to the added/removed index of the labels above

              J Offline
              J Offline
              JonB
              wrote on 26 Aug 2022, 12:11 last edited by JonB
              #8

              @Nevez
              Then as that link tells you, you will have to implement your own ADD COLUMN statements for MySQL, whether as part of overriding insertColumns() or not. The supplied SQL driver does not implement it for you (maybe because it varies across SQL implementations, it has many possible options, etc.).

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 26 Aug 2022, 12:16 last edited by
                #9

                What you want to do is called schema alteration. The way that can be done varies depending on the underlying DB system you use. SQLite for example has the ALTER TABLE but that is typically something that you do not do just on a whim.

                Altering a table by adding or removing a column can have far reaching consequences. One simple thing, when you add a new column, what goes in it ? Does it have a default value ? Will it be part of the indexing of the table ? What happens to all the rows that the table contains currently ?

                ORM like Django implements provide facilities to do database migrations and these migrations are steps that you do with care to avoid destroying your current database.

                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
                • N Offline
                  N Offline
                  Nevez
                  wrote on 26 Aug 2022, 12:27 last edited by Nevez
                  #10

                  @SGaist said in drag-and-drop columns.:

                  Basit bir şey, yeni bir sütun eklediğinizde içine ne giriyor? Varsayılan bir değeri var mı? Tablonun indekslenmesinin bir parçası olacak mı? Şu anda tablonun içerdiği tüm satırlara ne olur?

                  Like the photo I posted above. Each label represents a column in a database. Therefore, when a new column is added, the information of the column with that label text should come from the database.

                  likewise for the deleted column; The column with this label text should be detected and deleted from the table.

                  So I'm sorry I'll ask again. How exactly should I proceed?

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 26 Aug 2022, 19:03 last edited by
                    #11

                    Something is highly unclear here.

                    Do you want to simply hide and show the corresponding columns in your GUI or alter the table in the database (beside modifying your UI) ?

                    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
                    • N Offline
                      N Offline
                      Nevez
                      wrote on 27 Aug 2022, 09:27 last edited by
                      #12

                      Of course, if possible, I just want to add hiding through the view. However, since this hiding addition will depend on the column names on the labels, the correct column information must be sent to the right place. So in this case, I think that operations should be done on the model. What do you think?

                      J 1 Reply Last reply 27 Aug 2022, 10:20
                      0
                      • N Nevez
                        27 Aug 2022, 09:27

                        Of course, if possible, I just want to add hiding through the view. However, since this hiding addition will depend on the column names on the labels, the correct column information must be sent to the right place. So in this case, I think that operations should be done on the model. What do you think?

                        J Offline
                        J Offline
                        JonB
                        wrote on 27 Aug 2022, 10:20 last edited by JonB
                        #13

                        @Nevez
                        This is not the way to think of it. You do not arrange your base database model/table to suit what you might or might not want to show in a view. Either you want to add new columns of genuine data to the database or you do not. UPDATE Oh, I just saw you only want to hide columns, not add extra ones. Although earlier I thought you were saying you want to add columns.

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 27 Aug 2022, 11:04 last edited by
                          #14

                          So if it is only visual adding/removing of existing columns, then QTableView's setColumnHidden is what you want to use. With that your model is not affected at all.

                          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
                          2
                          • N Offline
                            N Offline
                            Nevez
                            wrote on 31 Aug 2022, 15:05 last edited by Nevez
                            #15

                            yes, this is a good method. but i am wondering if there is any way i can find out this.
                            For example, suppose you have a tableview with 10 columns loaded with a model.
                            When I hide the column in the 5.index with the "hideColumn(5)" method on this tableview,
                            According to the view, the index numbers of the columns after the 5th index should decrease by one.
                            example: (4- [5] --- 6 -7 -8 -9 -10 --->>> 4 - [hided] ---- 5 -6 -7 -8 - 9 )

                            But I check it with visualindex method , index numbers do not changing.
                            but i need to do this. Because When I hide the column, the index numbers of the labels decrease by one because the label in the layout above that column is also hidden.

                            M 1 Reply Last reply 31 Aug 2022, 15:14
                            0
                            • N Nevez
                              31 Aug 2022, 15:05

                              yes, this is a good method. but i am wondering if there is any way i can find out this.
                              For example, suppose you have a tableview with 10 columns loaded with a model.
                              When I hide the column in the 5.index with the "hideColumn(5)" method on this tableview,
                              According to the view, the index numbers of the columns after the 5th index should decrease by one.
                              example: (4- [5] --- 6 -7 -8 -9 -10 --->>> 4 - [hided] ---- 5 -6 -7 -8 - 9 )

                              But I check it with visualindex method , index numbers do not changing.
                              but i need to do this. Because When I hide the column, the index numbers of the labels decrease by one because the label in the layout above that column is also hidden.

                              M Offline
                              M Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 31 Aug 2022, 15:14 last edited by
                              #16

                              @Nevez
                              Hi
                              Maybe you can use logical index instead

                              https://uvesway.wordpress.com/2013/01/08/qheaderview-sections-visualindex-vs-logicalindex/

                              C 1 Reply Last reply 31 Aug 2022, 15:18
                              1
                              • M mrjj
                                31 Aug 2022, 15:14

                                @Nevez
                                Hi
                                Maybe you can use logical index instead

                                https://uvesway.wordpress.com/2013/01/08/qheaderview-sections-visualindex-vs-logicalindex/

                                C Offline
                                C Offline
                                Christian Ehrlicher
                                Lifetime Qt Champion
                                wrote on 31 Aug 2022, 15:18 last edited by
                                #17

                                @mrjj said in drag-and-drop columns.:

                                Maybe you can use logical index instead

                                Not maybe - it's a must. The visual index is... a visual index so it's not reliable when trying to access the underlying data from the outside.

                                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                Visit the Qt Academy at https://academy.qt.io/catalog

                                1 Reply Last reply
                                3
                                • N Offline
                                  N Offline
                                  Nevez
                                  wrote on 1 Sept 2022, 07:14 last edited by Nevez 9 Jan 2022, 07:20
                                  #18

                                  my problem is that the visual array doesn't give the result I want.
                                  That is, the indexes of the columns to the right of the hided column do not decreasing by one.

                                  According to the link @mrjj gave , I guess for this to happen, if I delete a column from the model, The indexes to the right of the deleted column decrease by one.
                                  This was a little bad for me.

                                  J 1 Reply Last reply 1 Sept 2022, 07:27
                                  0
                                  • N Nevez
                                    1 Sept 2022, 07:14

                                    my problem is that the visual array doesn't give the result I want.
                                    That is, the indexes of the columns to the right of the hided column do not decreasing by one.

                                    According to the link @mrjj gave , I guess for this to happen, if I delete a column from the model, The indexes to the right of the deleted column decrease by one.
                                    This was a little bad for me.

                                    J Offline
                                    J Offline
                                    JonB
                                    wrote on 1 Sept 2022, 07:27 last edited by
                                    #19

                                    @Nevez
                                    Perhaps you need to give a tiny example illustrating what you claim. Although I haven't used visual indexes, I would expect that after hiding a column the column(s) to the right would have visual indexes one less than the model indexes they show. Note that the model indexes will not change in any way: normally the visual index is the same as the model index, but once you hide a column they will differ. Is that not what you find, or not what your expectation is?

                                    1 Reply Last reply
                                    0
                                    • N Offline
                                      N Offline
                                      Nevez
                                      wrote on 1 Sept 2022, 07:38 last edited by Nevez 9 Jan 2022, 07:38
                                      #20

                                      @JonB said in drag-and-drop columns.:

                                      I would expect that after hiding a column the column(s) to the right would have visual indexes one less than the model indexes they show.

                                      Unfortunately, I tested it, it does not decrease.

                                      @JonB said in drag-and-drop columns.:

                                      normally the visual index is the same as the model index, but once you hide a column they will differ.

                                      No, as I said, when we hide the column, the visual index numbers still do not change (unless we move the columns). So the model index is the same as the visual index.

                                      J 1 Reply Last reply 1 Sept 2022, 07:48
                                      0
                                      • N Nevez
                                        1 Sept 2022, 07:38

                                        @JonB said in drag-and-drop columns.:

                                        I would expect that after hiding a column the column(s) to the right would have visual indexes one less than the model indexes they show.

                                        Unfortunately, I tested it, it does not decrease.

                                        @JonB said in drag-and-drop columns.:

                                        normally the visual index is the same as the model index, but once you hide a column they will differ.

                                        No, as I said, when we hide the column, the visual index numbers still do not change (unless we move the columns). So the model index is the same as the visual index.

                                        J Offline
                                        J Offline
                                        JonB
                                        wrote on 1 Sept 2022, 07:48 last edited by
                                        #21

                                        @Nevez
                                        OK, I've had a search. This was covered in the https://uvesway.wordpress.com/2013/01/08/qheaderview-sections-visualindex-vs-logicalindex/ reference @mrjj gave you, did you read it?

                                        Visual indexes tell us the current position that a given section occupies in the header.

                                        However there is a detail one has to be aware of: hiding/showing a given section (calling QHeaderView.hideSection method) does NOT change its visual index as one could expect.

                                        So it's perfectly clear: visual indexes are for when you re-order the view columns, but if you only hide a column it (and subsequent columns) still retain their index into the header columns.

                                        As I say, I haven't used visual indexes/hiding of columns. But if there is not some better way you would need to write code to map from on-screen-visible columns to underlying column numbers by taking into account which column(s) are hidden where. Which is just some code to write.

                                        1 Reply Last reply
                                        1

                                        12/21

                                        27 Aug 2022, 09:27

                                        • Login

                                        • Login or register to search.
                                        12 out of 21
                                        • First post
                                          12/21
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Users
                                        • Groups
                                        • Search
                                        • Get Qt Extensions
                                        • Unsolved