Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Context menu in QListWidget - reference to the item
Forum Updated to NodeBB v4.3 + New Features

Context menu in QListWidget - reference to the item

Scheduled Pinned Locked Moved Qt Creator and other tools
1 Posts 1 Posters 1.9k 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.
  • N Offline
    N Offline
    never_ever
    wrote on last edited by
    #1

    Hi,
    I have problem with context menu. I have created context menu in QListWidget, and now menu shows after mouse right clicking. I have some QActions there and I want to call the proper action for the the item that menu was showed.
    I hope I explain it clearly.

    This is piece of my code to show context menu:
    @
    void MyClass::on_listWidget_customContextMenuRequested(const QPoint& pos)
    {
    QListWidgetItem* widget = ui->listWidget->itemAt(pos);
    if(widget != 0)
    {
    int row = ui->listWidget->row(widget);
    QString text = widget->text();
    contextMenu_ = new QMenu(ui->listWidget);
    if(pos != QPoint(0,0))
    {
    QPoint pointGlobal;
    pointGlobal = mapToGlobal(pos);

            QAction* menuItem1 = new QAction("action 1", 0);
            connect(menuItem1, SIGNAL(triggered()),
                    this, SLOT(getContextMenuAction
            contextMenu_ -> addAction(menuItem1);
    
            QAction* menuItem2 = new QAction("action 2", 0);
            connect(menuItem2, SIGNAL(triggered()),
                    this, SLOT(getContextMenuAction()));
            contextMenu_ -> addAction(menuItem2);
    
            contextMenu_->exec(point);
        }
    }
    

    }
    @

    In that way I get menu and then after clicking on action getContextMenuAction method is called. But in the same moment I loose info on which item of the list the menu was clicked (I need that info). Is there any way to get that info?

    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