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 view - problems with selection
Qt 6.11 is out! See what's new in the release blog

Custom view - problems with selection

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 1.8k 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.
  • K Offline
    K Offline
    Kicer86
    wrote on last edited by
    #1

    Hi

    I've a custom view which is meant to be used with list-like models (one column, n-rows).
    My view displays items horizontaly, but wraps when right edge is reached. Here is an example:

    Consider model with 10 items (one item per row in 1 column).
    My view would display them like that:

    +---------------------------------+
    | Item1   Item2   Item3   Item4   |
    | Item5   Item6   Item7   Item8   |
    | Item9   Item10                  |
    |                                 |
    +---------------------------------+
    

    I hope it is clear. The problem I have is selection. I wish I could have the bahavior like that: when user clicks Item2 and then clicks Item6 with shift, items 2, 3, 4, 5 and 6 should be selected. However Qt framework calls setSelection() in my view with a rect which covers Item2 and Item6. In a general case I'm unable to figure out which items should I pass to selection model to get my desired behavior. I went through QAbstractItemView's doc and I cannot see anything that could help me. Any ideas or suggestions?

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

      Hi,

      What widget are you using for that ?

      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
      • K Offline
        K Offline
        Kicer86
        wrote on last edited by
        #3

        I've a custom class for this view derived directly from QAbstractItemView.

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

          Then it would likely be nice to share the code you are using for the view.

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

          K 1 Reply Last reply
          0
          • SGaistS SGaist

            Then it would likely be nice to share the code you are using for the view.

            K Offline
            K Offline
            Kicer86
            wrote on last edited by
            #5

            @SGaist
            here you go: images tree view. In line 249 (const std::deque<QModelIndex> linear_selection = convertToLinearSelection(items);) I was trying to convert rect into something that suits me, but it is working only under certain circumstances.

            However I think that code is irrelevant here. I just have very untypical view which arranges items in different way they are stored in model. Qt framework sends me selection as a rect which doesn't allow me to select items the way I want.

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

              Did you already saw the using a selection model part of the Model View Programming chapter ?
              There's also the Model View tutorial that could be of interest.

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

              K 1 Reply Last reply
              0
              • SGaistS SGaist

                Did you already saw the using a selection model part of the Model View Programming chapter ?
                There's also the Model View tutorial that could be of interest.

                K Offline
                K Offline
                Kicer86
                wrote on last edited by
                #7

                @SGaist Thank you for your interest however I'm afraid we do not understand each other.
                I'll deal with my problem by overriding QWidget::mousePressEvent and doing my own clicks interpretation there to generate proper selection.

                If you would like to see visualtion of my problem you can compile http://doc.qt.io/qt-5/qtwidgets-itemviews-chart-example.html example which also suffers from the same problem as I do.
                Select with rectangle any two consecutive elements and only these two will get selected.
                One exception from this rule: select biggest blue item and the green one above it. Whole chart will be selected. This is because Qt framework sends selection as a rect which covers first and last item and in my case I'm unable to figure out which two items were actualy selected.

                Regards.

                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