×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    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);
    }

  2. #2
    Registered User
    Join Date
    Aug 2010
    Posts
    6

    Re: close window menu programmatically

    Hi, I meet the same question.Are you find the answer?
    Thank you!

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

    Re: close window menu programmatically

    Quote Originally Posted by blueskygate View Post
    Hi, I meet the same question.Are you find the answer?
    Thank you!
    I definitely did.

  4. #4
    Registered User
    Join Date
    Aug 2010
    Posts
    6

    Re: close window menu programmatically

    I use your code in symbian emulator of carbide v2.6.3, the symbian SDK is S60_3rd_FP2_SDK_v1.1,the QT SDK is 4.6.3,but the three slots don't run,why?

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

    Re: close window menu programmatically

    Note, that hovered signal is not emitted on touch devices.

Similar Threads

  1. close cakninformationnote programmatically
    By alessandro__ in forum Symbian
    Replies: 8
    Last Post: 2010-03-30, 15:25
  2. close window menu programmatically
    By mabdelaal in forum Nokia N9
    Replies: 4
    Last Post: 2010-02-24, 22:31
  3. Close Widget with Window.close() not working
    By stephen.cheung in forum Symbian
    Replies: 6
    Last Post: 2009-09-04, 09:54
  4. How to close a Widget programmatically?
    By jappit in forum Symbian
    Replies: 2
    Last Post: 2008-04-16, 16:02
  5. programmatically close an CAknForm
    By strike_noir in forum Symbian User Interface
    Replies: 2
    Last Post: 2007-09-11, 09:41

Posting Permissions

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