Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Triggering Qt custom context menu in android
Forum Update on Monday, May 27th 2025

Triggering Qt custom context menu in android

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
qt 5.14.2androidqtcontext menu
1 Posts 1 Posters 527 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.
  • P Offline
    P Offline
    Parsa Mousavi
    wrote on 15 Aug 2020, 09:52 last edited by
    #1

    Hello everybody.I'm trying to get started with android development using Qt and now I want to create a custom context menu for android in C++.

    What I've done so far is as follows:

    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        ui->lcdNumber->setContextMenuPolicy(Qt::CustomContextMenu);
        connect(ui->lcdNumber , SIGNAL(customContextMenuRequested(const QPoint &)) \
                , this , SLOT(showContextMenu(const QPoint &)));
    }
    
    void MainWindow::showContextMenu(const QPoint& point)
    {
        Q_UNUSED(point);
    
        //To open up the menu in the cursor position instead of the widget's top-left point
        QPoint mousePos = QCursor::pos();              
    
        QMenu *cMenu = new QMenu(tr("Sample Context Menu"));
    
        QAction closeAction("Close" , this);
        QAction yetAnotherAction("Yet another action" , this);
        QObject::connect(&closeAction , SIGNAL(triggered()) , this , SLOT(close()));
    
        cMenu->addAction(&yetAnotherAction);
        cMenu->addAction(&closeAction);
        cMenu->exec(mousePos);
    }
    

    This is just a demo. It works well in desktop when I right-click the widget lcdNumber but in android I'm not able to open up the menu by long-clicking(i.e touching and holding) it.

    Also the example mentioned here using QtQuick doesn't work for me and results in this error:

    LOGCAT: W libmenuDemo-qtquick_armeabi-v7a.so: QMetaObject::invokeMethod: No such method QQuickRootItem::inputMethodQuery(Qt::InputMethodQuery,QVariant)
    

    How can I achieve that?

    1 Reply Last reply
    0

    1/1

    15 Aug 2020, 09:52

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved