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. Clicking header of QTableView selects top row and causes QTAbleView to emit clicked

Clicking header of QTableView selects top row and causes QTAbleView to emit clicked

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 2.5k 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
    MoschopsRedux
    wrote on last edited by
    #1

    I have a QTableView. It has a header. I'm stuck using QT 4.something

    Clicking on the header changes the row selected. So if I have row five selected, and I click a column in the header, the top row visible becomes selected. No sorting or anything.

    I don't want this.

    Also, I have connected the QTableView clicked signal to a function, and clicking on the header seems to make that signal fire. I also don't want this.

    I want clicking on the header to NOT change the selected row, and also to NOT cause QTableView to fire its clicked signal.

    How can I achieve this?

    1 Reply Last reply
    0
    • Chris HennesC Offline
      Chris HennesC Offline
      Chris Hennes
      wrote on last edited by
      #2

      Two questions for you: have you called setSortingEnabled on your table? And are you using setHeaderData to set the role of the header to Qt::DisplayRole?

      Chris Hennes, Pioneer Library System

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

        A little unfortunately, I'm maintaining some code in which what I'm working with is a view inherited from QTableView, and a header inherited from QHeaderView.

        That said, I think the answer to your first question must be yes, because I spent some time fixing sorting earlier and it does sort (i.e. click header section, and the rows rearrange themselves).

        The second; I do not know. I am looking.... The header sections have words in them, so something must be setting that.

        1 Reply Last reply
        0
        • Chris HennesC Chris Hennes

          Two questions for you: have you called setSortingEnabled on your table? And are you using setHeaderData to set the role of the header to Qt::DisplayRole?

          M Offline
          M Offline
          MoschopsRedux
          wrote on last edited by
          #4

          Yes, I believe setHeaderData is being used.

          However, I don't understand what you mean by "set the role of the header to Qt::DisplayRole". I thought that Qt::DisplayRole was the role of various data; I don't understand how an entire header's role can be Qt::DisplayRole.

          mrjjM 1 Reply Last reply
          0
          • M MoschopsRedux

            Yes, I believe setHeaderData is being used.

            However, I don't understand what you mean by "set the role of the header to Qt::DisplayRole". I thought that Qt::DisplayRole was the role of various data; I don't understand how an entire header's role can be Qt::DisplayRole.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @MoschopsRedux
            Hi
            The roles is part of the call
            bool QAbstractItemModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole)

            But as u can se its default Qt::EditRole so i thinki
            @Chris-Hennes ask if u set it as Qt::DisplayRole instead.

            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