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. [Solved] Showing QMenu in QListView
Forum Updated to NodeBB v4.3 + New Features

[Solved] Showing QMenu in QListView

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

    Hello All Qt developers!,

    I've been recently working on widget which presents some items inside QListView widget. Let's say it presents some files from a disk directory. I'm using subclassed and customized QAbstractItemModel to hold data and this works fine. The problem I've be facing is with showing QMenu. I created QMenu and I set contextMenuPolicy to: Qt::CustomContextMenu. So far everything is ok, because parent widget emits QWidget::customContextMenuRequested ( const QPoint & pos ) signal. This works as long as I use mouse (right mouse button - standard Qt solution). The problem appears when I want to show QMenu with "menu" button (application is being developed for embedded system device, which won't have a mouse, but will have "menu" button). I call QMenu::exec() and QMenu appears but at top left corner at QPoint(0,0).

    What I want to achieve is to find out/gather the QPoint for every item that is shown by QListView and with this point show QMenu next to item's name or icon. Do You have any idea how can I get this point from QListView or even more generally from QAbstractItemView classes?

    I figured out solution with method:
    @QModelIndex QAbstractItemView::indexAt ( const QPoint & point )@

    I simply recieved current selected item with: currentIndex() method and then I compared this item with item returned by indexAt(...) method. It's not very elegant, so maybe You know any other simple way?

    Robert

    1 Reply Last reply
    0
    • P Offline
      P Offline
      poor_robert
      wrote on last edited by
      #2

      All "Mad Scientiests" don't You have any idea??

      Robert

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

        Hi,

        might
        @
        QAbstractItemView::visualRect ( const QModelIndex & index ) const
        @

        be of any use for you? This seems to return the bounding rect of the index, so you could choose a good popup position from it.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          poor_robert
          wrote on last edited by
          #4

          Thank You very much!

          I have no idea how I missed this in documentation.

          Solved!

          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