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. QTreeView, are pos in customContextMenuRequested and pos in indexAt the same?
Forum Updated to NodeBB v4.3 + New Features

QTreeView, are pos in customContextMenuRequested and pos in indexAt the same?

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

    MyTreeView is derived from QTreeView

    pos in MyTreeView::customContextMenuRequested is relative to MyTreeView::viewport()

    For the code snippets below, which one is right?

    void MyTreeView::on_myTreeView_customContextMenuRequested(const QPoint &pos)
    {
        QModelIndex index = indexAt(pos);
    }
    
    void MyTreeView::on_myTreeView_customContextMenuRequested(const QPoint &pos)
    {
        QPoint pos_in_view = mapTo(this, pos);
        QModelIndex index = indexAt(pos_in_view);
    }
    
    eyllanescE 1 Reply Last reply
    0
    • jronaldJ jronald

      MyTreeView is derived from QTreeView

      pos in MyTreeView::customContextMenuRequested is relative to MyTreeView::viewport()

      For the code snippets below, which one is right?

      void MyTreeView::on_myTreeView_customContextMenuRequested(const QPoint &pos)
      {
          QModelIndex index = indexAt(pos);
      }
      
      void MyTreeView::on_myTreeView_customContextMenuRequested(const QPoint &pos)
      {
          QPoint pos_in_view = mapTo(this, pos);
          QModelIndex index = indexAt(pos_in_view);
      }
      
      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by eyllanesc
      #2

      @jronald The first is the correct one:

      QModelIndex QAbstractItemView::indexAt(const QPoint &point) const
      Returns the model index of the item at the viewport coordinates point.

      In the base class this is a pure virtual function.

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      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