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. Selection row doesn't work in qtableview
Forum Updated to NodeBB v4.3 + New Features

Selection row doesn't work in qtableview

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 2.0k 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.
  • M Offline
    M Offline
    medihech
    wrote on last edited by
    #1

    Hi.

    I am using qtableview and my own model and own delegator to show some data. I am using the following code to highlight the cell when is selected by the user :
    view->setSelectionBehavior(QAbstractItemView::SelectRows);
    view->setSelectionMode(QAbstractItemView::SingleSelection);

    However, it doesn't work. Could you tell me please what I am doing wrong?

    Thanks.

    VRoninV 1 Reply Last reply
    0
    • M medihech

      Hi.

      I am using qtableview and my own model and own delegator to show some data. I am using the following code to highlight the cell when is selected by the user :
      view->setSelectionBehavior(QAbstractItemView::SelectRows);
      view->setSelectionMode(QAbstractItemView::SingleSelection);

      However, it doesn't work. Could you tell me please what I am doing wrong?

      Thanks.

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @medihech said in Selection row doesn't work in qtableview:

      I am using the following code to highlight the cell when is selected by the user

      It's not clear what you mean by this

      my own model

      how does the flags() method look like in the model?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • M Offline
        M Offline
        medihech
        wrote on last edited by
        #3

        By my own model, I mean I created a custom model that inherits from QAbstractTableModel.

        The flags looks like:

        Qt::ItemFlags TestModel::flags(const QModelIndex &index) const
        {
        return Qt::ItemIsEditable | QAbstractTableModel::flags(index);
        }

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          Sorry, my bad.
          I was referring to "highlight the cell when is selected by the user" being vague

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          0
          • M Offline
            M Offline
            medihech
            wrote on last edited by
            #5

            To get something similar to this when the user clicks the cell :
            d225ab66-2e30-4adc-89a1-19242af4365d-image.png

            The code I sent you before is to highlight the cell:

            0cdf8910-3b99-40be-afca-83ccedb725f6-image.png

            But it doesn't work either.

            I don't if it could be related, but I also reimplemented the paint method of my delegator, not sure if it is the reason I cannot highlight the cell.

            Thanks in advance!

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

              Hi,

              You should show the implementation of your delegate, you are likely not handling the selected state there.

              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
              • M Offline
                M Offline
                medihech
                wrote on last edited by
                #7

                Hi.

                I am afraid I cannot show the whole implementation unless it is something more specific. Could you tell me please what do you mean with "handling the select state" ? Could you show me an simple example how to handle it ?

                Thank you very much for your help. It is very much appreciated.

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

                  The Star Delegate example shows it.

                  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

                  • Login

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