×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    32

    close window menu programmatically

    Hi All,

    How can I know that the menu opened, and how can i close it programmatically.

    Thank you,

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: close window menu programmatically

    Quote Originally Posted by mabdelaal View Post
    Hi All,

    How can I know that the menu opened, and how can i close it programmatically.

    Thank you,
    Use QWidget::visible
    http://doc.trolltech.com/4.6/qwidget.html#visible-prop

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    32

    Re: close window menu programmatically

    Quote Originally Posted by divanov View Post
    I tried it but not work.
    I created menus using QMenuBar::addAction(QAction*), to take the style of maemo menus.

    Thank you,

  4. #4
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: close window menu programmatically

    Quote Originally Posted by mabdelaal View Post
    I tried it but not work.
    That means you did something wrong.
    Quote Originally Posted by mabdelaal View Post
    I created menus using QMenuBar::addAction(QAction*), to take the style of maemo menus.
    addAction creates QAction, not a QMenu as you can guess from the method name. Also it's not clear to me how style of Maemo menus is involved in this.

  5. #5
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: close window menu programmatically

    main.cpp
    Code:
    #include <QMainWindow>
    #include <QMenuBar>
    #include <QDebug>
    
    #include "application.h"
    
    int
    main (int argc, char **argv)
    {
        Application app(argc, argv);
    
        QAction action(QString("Action"), 0);
    
        QMenu menu("Fremantle");
        menu.addAction(&action);
    
        QObject::connect(&menu, SIGNAL(aboutToShow()),
                         &app, SLOT(menuAboutToShow()));
        QObject::connect(&menu, SIGNAL(aboutToHide()),
                         &app, SLOT(menuAboutToHide()));
        QObject::connect(&menu, SIGNAL(hovered(QAction*)),
                         &app, SLOT(menuHovered(QAction*)));
    
        QMainWindow win;
        win.menuBar()->addMenu(&menu);
        win.show();
    
        return app.exec();
    }
    application.h:
    Code:
    #ifndef APPLICATION_H
    #define APPLICATION_H
    
    #include <QApplication>
    #include <QAction>
    
    class Application : public QApplication
    {
        Q_OBJECT
    public:
        Application(int &argc, char **argv);
    
    protected slots:
        void menuAboutToShow();
        void menuAboutToHide();
        void menuHovered(QAction* action);
    };
    
    #endif // APPLICATION_H
    application.cpp:
    Code:
    #include <QDebug>
    
    #include "application.h"
    
    Application::Application(int &argc, char **argv)
        : QApplication(argc, argv)
    {
    }
    
    void Application::menuAboutToShow()
    {
        QWidget *menu = qobject_cast<QWidget *>(sender());
        qDebug() << __PRETTY_FUNCTION__ << menu->isVisible();
    }
    
    void Application::menuAboutToHide()
    {
        QWidget *menu = qobject_cast<QWidget *>(sender());
        qDebug() << __PRETTY_FUNCTION__ << menu->isVisible();
    }
    
    void Application::menuHovered(QAction* action)
    {
        Q_UNUSED(action);
    
        QWidget *menu = qobject_cast<QWidget *>(sender());
    
        qDebug() << __PRETTY_FUNCTION__ << menu->isVisible();
    
        menu->setVisible(false);
    }

Similar Threads

  1. How to close a Widget programmatically?
    By jappit in forum Symbian
    Replies: 2
    Last Post: 2008-04-16, 16:02
  2. creating menu and sub menu
    By hasiamar in forum Symbian User Interface
    Replies: 3
    Last Post: 2006-10-23, 16:21
  3. Symbian C++ - Series 60 - Populating listbox in window when apps is launched?
    By periakaruppan in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2005-07-29, 03:31
  4. Replies: 0
    Last Post: 2005-07-29, 03:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×