Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Creating a menu



  • I'm trying to create a menu, so I tried this.

    @
    ui->setupUi(this);

    //Creating actions
    insert = new QAction(tr("Insert"),this);
    connect(insert, SIGNAL(triggered()), this, SLOT(on_InsertButton_clicked()));
    detect = new QAction(tr("Check"),this);
    connect(detect, SIGNAL(triggered()), this, SLOT(on_DetectButton_clicked()));
    about = new QAction(tr("About"),this);
    connect(about, SIGNAL(triggered()), this, SLOT(on_AboutPushButton_clicked()));
    
    //Creating menu
    eyemenu = new QMenu("Options", this);
    eyemenu->addAction(insert);
    eyemenu->addAction(detect);
    eyemenu->addSeparator();
    eyemenu->addAction(about);
    

    @

    But, nothing show up on the left side of the menu on Symbian. Just the right 'Exit' button.
    Is there any mistake on this? Thanks.



  • If you are using a QMainWindow you should use a menuBar() variable in order to add the menu there like:

    @
    ui->menubar->addMenu(eyemenu);
    @



  • if you wish to add a popup menu yuo can do something like this
    @
    void ListWidget::customContentsMenu( const QPoint &pos )
    {
    QPoint globalPos = this->mapToGlobal(pos);
    menu->exec( globalPos );
    }
    @



  • Thanks,

    I created a menubar with Qt creator's UI. It seems to be working ok, but I also get an "actions" option when I run it on the phone (which does nothing). No idea what that is :o



  • I don't know if it's a bug or a feature but the steps for removing the actions option are:

    Go to the Qt Designer (you can do this in the code as well)

    Select every Widget in your form

    In the properties pane find contextMenuPolicy and change it to NoContextMenu for every widget inside your form (could be a QWidget, QDialog or a QMainWindow).

    See the screenshot below

    !http://i.imgur.com/07z8J.png(pic)!



  • Thanks, actions option is gone. :)



  • I probably have to write a wiki article on how to remove the strange actions menu.



  • [quote author="Milot Shala" date="1295900993"]I don't know if it's a bug or a feature but the steps for removing the actions option are:

    Go to the Qt Designer (you can do this in the code as well)

    Select every Widget in your form

    In the properties pane find contextMenuPolicy and change it to NoContextMenu for every widget inside your form (could be a QWidget, QDialog or a QMainWindow).

    See the screenshot below

    !http://i.imgur.com/07z8J.png(pic)![/quote]

    That's great :)




Log in to reply