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. CustomContext menu is not displaying in proper position
Forum Updated to NodeBB v4.3 + New Features

CustomContext menu is not displaying in proper position

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 5.7k 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.
  • A Offline
    A Offline
    aurora
    wrote on last edited by
    #1

    The context menu in program is not displaying at the position of the pointer...it is displaying somewhere else...
    Please suggest me what changes i need to do for my program?

    The code is:
    @
    void MainWindow::ProvideContextMenu(const QPoint &pos)
    {
    QTableWidgetItem *item=filesTable->itemAt(pos);

    QString cell=item->text();
            cout<<"EVENT GENERATED..."<<cell.toStdString()<<endl;
    //QString item=filesTable->itemAt(pos);
    QAction *pAddAction= new QAction("add",filesTable);
    QAction *pSplitAction= new QAction("SPLIT",filesTable);
    QMenu *pContextMenu = new QMenu( this);
    pContextMenu->addAction(pAddAction);
    pContextMenu->addAction(pSplitAction);
    pContextMenu->exec&#40;mapToGlobal(pos&#41;);
    

    }
    @

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KA51O
      wrote on last edited by
      #2

      Can you please also post the code showing how you get the position you're using as the functions parameter ? Is it from the event->pos() retrieved in a mousePressEvent(QMouseEvent event) function or from QCursor::pos()... ?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aurora
        wrote on last edited by
        #3

        @ connect(filesTable,SIGNAL(customContextMenuRequested(const QPoint &)),this,SLOT(ProvideContextMenu(const QPoint &)));
        @
        this is the code which generates the signal

        1 Reply Last reply
        0
        • K Offline
          K Offline
          KA51O
          wrote on last edited by
          #4

          Hmm. Have you tried move your ProvideContextMenu(const QPoint &pos) function to the filesTable class implementation. This way you would not have to map the position.

          It's just a guess but maybe your problem is related to this exception stated in "the doc of customContextMenuRequested(..)":http://developer.qt.nokia.com/doc/qt-4.8/qwidget.html#customContextMenuRequested:

          bq. The position pos is the position of the context menu event that the widget receives. Normally this is in widget coordinates. The exception to this rule is QAbstractScrollArea and its subclasses that map the context menu event to coordinates of the viewport().

          Since QAbstractScrollArea is inherited by QAbstractItemView, QGraphicsView, QMdiArea, QPlainTextEdit, QScrollArea, and QTextEdit

          1 Reply Last reply
          0
          • A Offline
            A Offline
            aurora
            wrote on last edited by
            #5

            hmmmm...:(

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              There are mapping methods available in every QWidget instance...

              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