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 Column Click and Select
QtWS25 Last Chance

QTableView Column Click and Select

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 1.9k Views
  • 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.
  • Q Offline
    Q Offline
    Qt.Jo.Ha
    wrote on last edited by
    #1

    Hi i have a table view
    I want Table view columns always have multiple selections so i apply QAbstractItemView::MultiSelection attribute.

    However, I had a problem. I want to make one of 10 columns not selectable even when clicked. The reason is that you want to do something different.

    Is there a way?

    JonBJ 1 Reply Last reply
    0
    • Q Qt.Jo.Ha

      Hi i have a table view
      I want Table view columns always have multiple selections so i apply QAbstractItemView::MultiSelection attribute.

      However, I had a problem. I want to make one of 10 columns not selectable even when clicked. The reason is that you want to do something different.

      Is there a way?

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

      @Qt-Jo-Ha
      Yes, your items/data must make sure it clears the Qt::ItemIsSelectable flag for that column.

      1 Reply Last reply
      3
      • Q Offline
        Q Offline
        Qt.Jo.Ha
        wrote on last edited by
        #3

        @JonB

        Thanks your answer !

        Not Selectable option was given in the flag of the view model, but it was not selected even if the column was selected.

        However, when a row is selected, the columns are not displayed as the rest of the selected columns. Can I solve this?

        JonBJ 1 Reply Last reply
        0
        • Q Qt.Jo.Ha

          @JonB

          Thanks your answer !

          Not Selectable option was given in the flag of the view model, but it was not selected even if the column was selected.

          However, when a row is selected, the columns are not displayed as the rest of the selected columns. Can I solve this?

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

          @Qt-Jo-Ha
          Not sure I understand your question.

          Once items are not selectable, then when you select a whole row those columns which are not selectable will not show with selected background color. That is what you wanted, you stated:

          I want to make one of 10 columns not selectable even when clicked.

          So, yes, they do not display as the rest of the columns in the row.

          1 Reply Last reply
          1
          • Q Offline
            Q Offline
            Qt.Jo.Ha
            wrote on last edited by Qt.Jo.Ha
            #5

            @JonB

            Thanks your answer

            This is the current situation

            b09cc31a-df0b-4460-a22e-91e18b00fa34-image.png

            When selectable items are selected I want the next picture.

            c03d9649-4299-41cc-bd3d-8eb6b798d4d7-image.png

            But now it is.

            ef98a507-9634-49ba-a82c-d652cf59e77a-image.png

            When a column is clicked, the row is selected.

            JonBJ 1 Reply Last reply
            0
            • Q Qt.Jo.Ha

              @JonB

              Thanks your answer

              This is the current situation

              b09cc31a-df0b-4460-a22e-91e18b00fa34-image.png

              When selectable items are selected I want the next picture.

              c03d9649-4299-41cc-bd3d-8eb6b798d4d7-image.png

              But now it is.

              ef98a507-9634-49ba-a82c-d652cf59e77a-image.png

              When a column is clicked, the row is selected.

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

              @Qt-Jo-Ha
              Yes, because if you want "non-selectable" it can't be selected, so it doesn't show in blue. That's precisely what you asked for, and what you get.

              So now the question is: what do you mean by wanting "non-selectable", since that's what you now have but do not want? You need to explain what you are looking for.

              For example, do you mean: "When a row is selected, I do want the column to be shown as selected, just like the other columns. But I just do not want that column to be clickable to select the row"? Is that what you want, something about you can't click to select the row on that column, but the column is selectable like all other columns in terms of it showing it is selected? Which seems like an odd requirement.... If it's that, you have instead to look at the clicks on the table, and not allow a row to be selected when the item clicked is in that column.

              1 Reply Last reply
              0
              • Q Offline
                Q Offline
                Qt.Jo.Ha
                wrote on last edited by
                #7

                @JonB

                Thank you so much for answering each time.

                What I want to do exactly There is a coloumn for selection and a column for deletion

                If you make a selection, you want the column that is not selectable to be drawn with the selected state.

                JonBJ 1 Reply Last reply
                0
                • Q Qt.Jo.Ha

                  @JonB

                  Thank you so much for answering each time.

                  What I want to do exactly There is a coloumn for selection and a column for deletion

                  If you make a selection, you want the column that is not selectable to be drawn with the selected state.

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

                  @Qt-Jo-Ha
                  I'm sorry, but I still don't find that you are explaining what it is you do want/need, as you're not distinguishable between selectable versus clickable.

                  I can only repeat what I said above, which is my best guess:

                  • If you want the column to show in blue just like the other columns, then just like them you must allow it to have the Qt::ItemIsSelectable flag.

                  • At that point, it is automatically clickable too. If you want to forbid that, you must deal with that at the mouse-click level, ignoring that if it's in your "non-clickable" column. So far as I know, that's what you'll need to do.

                  I still don't know why you want to forbid certain columns to be "click-to-select". If you want columns for "select" & "delete" those should (IMHO) have buttons (or links) to click on to accomplish, and again has nothing to do with whether the column cell, which does no harm to allow as normal selectable & clickable.

                  1 Reply Last reply
                  1
                  • Q Offline
                    Q Offline
                    Qt.Jo.Ha
                    wrote on last edited by
                    #9

                    @JonB

                    Thank you so much for the details. Everything you guess is correct.

                    Let's make it so that only the drawing is selected when processing the mouse click and selecting the corresponding row.

                    Thank you!

                    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