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. Getting QModelIndex from QHeaderView

Getting QModelIndex from QHeaderView

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.4k 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.
  • G Offline
    G Offline
    gaijinpunch
    wrote on last edited by
    #1

    Simple problem: I reimplemented QHeaderView and am spawning a menu when a section is right-clicked. I'd like part of that menu to have the text which is in the header. I need to get that from either the QAbstractTableModel or QSortFilterProxyModel. I've tried indexAt() in both the QHeaderView (which I'm not too surprised fails) and even QTableView to no avail.

    I could (probably) get the header data from model()->headerData() but there are caveats when there's a QSortFilterProxyModel inbetween them. It will map QModelIndex but not a header index. :-/

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

      Hi,

      What about logicalIndexAt ?

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

        I tried that. It's returning me an invalid index (row() & column() of -1).

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gaijinpunch
          wrote on last edited by
          #4

          Okay, logicalIndexAt() worked, when I used QMouseEvent::pos() and not QMosueEvent::globalPos(), so that was an error I overlooked.

          I think what has to be done now is call mapToSource() when using a proxy, then call headerData().

          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