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. How to do custom Selection in QTableWidget?
Forum Updated to NodeBB v4.3 + New Features

How to do custom Selection in QTableWidget?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.1k 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.
  • L Offline
    L Offline
    legarcon
    wrote on last edited by
    #1

    QTableWidget consists of several Selection Modi, which are selectable with the method

    setSelectionMode (QAbstractItemView::SelectionMode mode)

    None of the given modi fits the type of interactive selection i want to have. I want to implement a selection mode where when a user clicks in one table cell, and then shift+clicks in another table cell, the resulting selection is not a sum of columns and rows between these two, but starts from the first clicked cell, goes in read direction along row by row, ending by the second click. This is how it is implemented for example in windows explorer when you are having the grid / tiled view. I hope i made clear what i want to do.

    Do i need to overwrite the QItemSelectionModel or the QTableWidget? Where are the user clicks for selection are processed?

    This Question is related to Qt 4.8 Desktop Edition, C++

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      Hi and welcome to the forum!

      have a look at "this doc":http://qt-project.org/doc/qt-5.0/qtwidgets/model-view-programming.html#handling-selections-in-item-views

      It's explained with examples how to deal with this.

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • L Offline
        L Offline
        legarcon
        wrote on last edited by
        #3

        So following the instruction i need to write my own QItemSelectionModel.
        But there is a problem with it.

        QTableWidget->setSelectionModel does only accept QItemSelectionModel based class. But when i want to inherit from that, i need a QAbstractItemModel for its constructor, where do i get that from?
        Alternatively the instructions want me to use QAbstractTableModel. But also i can inherit from it with no problems, this is not accepted from the above given method. What to do now?

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

          Hi,

          You give it the model it must act on, in this case the QTableWidget's model

          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