• 菜单条 Menu Bar Action



    //
    .h /***Action**/ QAction * act_openImage; QAction * act_openVideo; QAction * act_openAudio; /***Menu***/ QMenu * menu_Image; QMenu * menu_Video; QMenu * menu_Audio;
    private:

    void createActions();

    void createMenus();
    public slots:
        void slotOpenImage();
        void slotOpenVideo();
        void slotOpenAudio();
    //.cpp
    
    void MainWindow::createActions()
    {
        act_openImage = new QAction(QIcon(":/main/res/图片.png"),tr("图片"),this);
        act_openVideo = new QAction(QIcon(":/main/res/视频.png"),tr("视频"),this);
        act_openAudio = new QAction(QIcon(":/main/res/音乐.png"),tr("音乐"),this);
    
        connect(act_openImage,SIGNAL(triggered(bool)),this,SLOT(slotOpenImage()));
        connect(act_openVideo,SIGNAL(triggered(bool)),this,SLOT(slotOpenVideo()));
        connect(act_openAudio,SIGNAL(triggered(bool)),this,SLOT(slotOpenAudio()));
    }
    
    void MainWindow::createMenus()
    {
        menu_Image = menuBar()->addMenu(tr("图片"));
                    //MenuBar()返回 menu bar for the main window
                    //addMenu() Append menu to the menu bar
        menu_Image->addAction(act_openImage);
    
        menu_Video = menuBar()->addMenu(tr("视频"));
        menu_Video->addAction(act_openVideo);
    
        menu_Audio = menuBar()->addMenu(tr("音频"));
        menu_Audio->addAction(act_openAudio);
    
    }

    效果:

  • 相关阅读:
    MySql--密码查看或修改
    javaweb学习--Servlet开发(一)
    javaweb学习--http协议
    Vue.js学习笔记(一)
    javascript事件处理
    javascript时间的相关操作
    代理模式(Proxy)
    单例模式(Singleton)
    ArrayBlockingQueue和LinkedBlockingQueue队列
    自增(++)和自减(--)运算符
  • 原文地址:https://www.cnblogs.com/azbane/p/8657262.html
Copyright © 2020-2023  润新知