Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Does TableView supports items selection?

Does TableView supports items selection?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 612 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.
  • D Offline
    D Offline
    Dmitriano
    wrote on last edited by
    #1

    Is there a way to make TableView select row and access selected row index?
    QT 5.13, QuickControls 2.

    ODБOïO 1 Reply Last reply
    0
    • D Dmitriano

      Is there a way to make TableView select row and access selected row index?
      QT 5.13, QuickControls 2.

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #2

      @dmitriano
      hi see this qt Blog comment, and it looks like there is still not selection aftera quick search

      Richard Moe Gustavsen
      August 31, 2018 at 10:51

      1. TableView itself does not (yet) contain any selection support. For now, you would need to store which rows/columns/items that are selected in a your own data structure (or e.g add a model role “selected” to you data model). Then bind that information/role to a selected state (e.g bgcolor) inside the delegate to show it as selected.
      2. rowSpan and colSpan are not available in this first release.
      3. Even if TableView itself has a fixed width of e.g 750px, the content view inside it that you flick around, can be of any size. And it’s always resized to fit the size of the table. So (normally) there will be no extra left-over space at the end that the last column could fill. But it might still make sense for tables that are smaller than the TableView size itself, or if you set a custom contentWidth. I’ll make a note.

      in QtQuick.Controls 1.4 there is a selection property

      D 1 Reply Last reply
      1
      • ODБOïO ODБOï

        @dmitriano
        hi see this qt Blog comment, and it looks like there is still not selection aftera quick search

        Richard Moe Gustavsen
        August 31, 2018 at 10:51

        1. TableView itself does not (yet) contain any selection support. For now, you would need to store which rows/columns/items that are selected in a your own data structure (or e.g add a model role “selected” to you data model). Then bind that information/role to a selected state (e.g bgcolor) inside the delegate to show it as selected.
        2. rowSpan and colSpan are not available in this first release.
        3. Even if TableView itself has a fixed width of e.g 750px, the content view inside it that you flick around, can be of any size. And it’s always resized to fit the size of the table. So (normally) there will be no extra left-over space at the end that the last column could fill. But it might still make sense for tables that are smaller than the TableView size itself, or if you set a custom contentWidth. I’ll make a note.

        in QtQuick.Controls 1.4 there is a selection property

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

        @lelev hi!
        If I have "selected" role (of type bool) in my model, for example, how do I set it to true when the user clicks on a cell (or row)? For example, if I add MouseArea to the delegate what should I do in its onClicked handler? Is there a common technique for updating the model from the delegate?

        ODБOïO IntruderExcluderI 2 Replies Last reply
        0
        • D Dmitriano

          @lelev hi!
          If I have "selected" role (of type bool) in my model, for example, how do I set it to true when the user clicks on a cell (or row)? For example, if I add MouseArea to the delegate what should I do in its onClicked handler? Is there a common technique for updating the model from the delegate?

          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by ODБOï
          #4

          @dmitriano hi,
          so what are you using now controls 1 or 2 ?

          @dmitriano said in Does TableView supports items selection?:

          Is there a common technique for updating the model from the delegate?

          it depends on your model, is it qml listmodel or QAbstractTableModel defined in c++ ?

          1 Reply Last reply
          0
          • D Dmitriano

            @lelev hi!
            If I have "selected" role (of type bool) in my model, for example, how do I set it to true when the user clicks on a cell (or row)? For example, if I add MouseArea to the delegate what should I do in its onClicked handler? Is there a common technique for updating the model from the delegate?

            IntruderExcluderI Offline
            IntruderExcluderI Offline
            IntruderExcluder
            wrote on last edited by
            #5

            @dmitriano said in Does TableView supports items selection?:

            @lelev hi!
            If I have "selected" role (of type bool) in my model, for example, how do I set it to true when the user clicks on a cell (or row)? For example, if I add MouseArea to the delegate what should I do in its onClicked handler? Is there a common technique for updating the model from the delegate?

            You can use ItemDelegate for example. If model set properly, then when clicked you can switch your role.
            Example:

            delegate: ItemDelegate {
                ...
                contentItem: ...
                onClicked: model.selected = !model.selected
                ...
                background: Rectangle {
                    visible: model.selected
                    color: "blue"
                    opacity: 0.5
                }
            }
            
            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