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] How tu use Actions on popup contextmenu previously created in Action Editor (QT Creator - QT 4.7) ??
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How tu use Actions on popup contextmenu previously created in Action Editor (QT Creator - QT 4.7) ??

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 5.2k 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.
  • I Offline
    I Offline
    inejose
    wrote on last edited by
    #1

    Hello,

    I'm newbie to Qt and C++.

    I created and Action (actionConnection) in QT Creator with Action Editor, as show here:

    !http://s14.postimage.org/7iri8oa9t/action_Connection.png(ActionEditor )!

    It works well and I can insert it in toolbar.

    But I would like to insert this action in a popup contextMenu when we right click on tree elements. This is my code for the ContextMenu:

    mainwindow.cpp

    @#include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::on_MainWindow_customContextMenuRequested(const QPoint &pos)
    {
    QMenu *menu = new QMenu();

    QAction *setupAction = new QAction("Setup", this);
    QAction *monitorAction = new QAction("Monitor", this);
    
      //*How can I refer here to actionConnection created on Action Editor?*
    
    menu->addAction(setupAction);
    menu->addAction(monitorAction);
    
    menu->exec(QCursor::pos());
    

    }@

    This is the result:

    !http://s7.postimage.org/bctn2qkp7/result.png(Result)!

    How can I insert the previously created MainWindow Action (actionConnect) in contextMenu (as in toolbar)?

    Thank you in advance for your help!!

    call it version 1.0 <a href="http://www.clicpsicologos.com">psicologo online</a> & <a href="http://www.isomus.com">musicoterapia</a>

    1 Reply Last reply
    0
    • M Offline
      M Offline
      miroslav
      wrote on last edited by
      #2

      The actions created in Designer are member variables of the ui object. Access them like this:
      ui->actionConnection...

      Mirko Boehm | mirko@kde.org | KDE e.V.
      FSFE Fellow
      Qt Certified Specialist

      1 Reply Last reply
      0
      • I Offline
        I Offline
        inejose
        wrote on last edited by
        #3

        Thank you miroslav. Now It works.

        This is the final working code:

        @void MainWindow::on_MainWindow_customContextMenuRequested(const QPoint &pos)
        {
        QMenu *menu = new QMenu();
        QAction *setupAction = new QAction("Setup", this);
        QAction *monitorAction = new QAction("Monitor", this);

        menu->addAction(setupAction);
        menu->addAction(monitorAction);
        
        menu->addAction(ui->actionConnection);
        
        menu->exec&#40;QCursor::pos(&#41;&#41;;
        

        }@

        call it version 1.0 <a href="http://www.clicpsicologos.com">psicologo online</a> & <a href="http://www.isomus.com">musicoterapia</a>

        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