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. Return value of QHeaderView ::logicalIndexAt is not accurate
Forum Updated to NodeBB v4.3 + New Features

Return value of QHeaderView ::logicalIndexAt is not accurate

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 362 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.
  • jronaldJ Offline
    jronaldJ Offline
    jronald
    wrote on last edited by jronald
    #1

    code as below, what's the bug?

    void MyTreeView::OnHeaderViewMouseRClick(bool checked)
    {
        QHeaderView * hv = header();
    
        QPoint pt = QCursor::pos();
    
        pt = hv->mapFromGlobal(pt);
    
        int logical_index = hv->logicalIndexAt(pt);
        QString s = QString::asprintf("%d", logical_index);
    
        QMessageBox::information(this, "info", s);
    }
    
    1 Reply Last reply
    0
    • jronaldJ Offline
      jronaldJ Offline
      jronald
      wrote on last edited by
      #5

      I've found the cause of the problem, mouse position when clicking on a menu item is different from the mouse position when popping up the context menu.

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

        Hi,

        What's the values you get ?
        What's the values you expect ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        jronaldJ 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          What's the values you get ?
          What's the values you expect ?

          jronaldJ Offline
          jronaldJ Offline
          jronald
          wrote on last edited by jronald
          #3

          @SGaist said in Return value of QHeaderView ::logicalIndexAt is not accurate:

          What's the values you get ?
          What's the values you expect ?

          47110a8f-1ea0-4cb0-883d-5433a7fdc27f-image.png

          The red sections and indexes are what's I got.
          The green sections and indexes are what's expected.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            You should print out pt - I would guess x is not 0 when you click on the very left side of the header view.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            0
            • jronaldJ Offline
              jronaldJ Offline
              jronald
              wrote on last edited by
              #5

              I've found the cause of the problem, mouse position when clicking on a menu item is different from the mouse position when popping up the context menu.

              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