Results 1 to 7 of 7

Thread: How to click and pop up submenu

  1. #1
    Join Date
    Mar 2010
    Posts
    25
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default How to click and pop up submenu

    Hello, what I want to do is merely pop up a sub-menu when I click on a button.

    Qt Code:
    1. connect(mybutton2, SIGNAL(clicked()), this, SLOT(call()));
    To copy to clipboard, switch view to plain text mode 

    The code above unable to do so. Does anybody knows how to do it?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to click and pop up submenu

    Use QPushButton::setMenu() or QWidget::setContextMenuPolicy() or create a custom menu in your slot and call exec with the current mouse position, or or or

  3. #3
    Join Date
    Mar 2010
    Posts
    25
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to click and pop up submenu

    Ha, I feel embrace to paste the code again.
    mybutton2->setContextMenuPolicy(Qt::ActionsContextMenu);
    After I click the button, still the same ..

    #include <QApplication>
    #include <QFont>
    #include <QPushButton>
    #include <QVBoxLayout>
    #include <QWidget>
    #include <QIcon>
    #include <qpixmap.h>
    #include <QAbstractButton>
    #include <QToolButton>
    #include <QStyle>
    #include <QtGui>
    #include <QApplication>
    #include "analogclock.h"

    class MyWidget : public QWidget
    {
    public:
    MyWidget(QWidget *parent = 0);

    public slots:
    void call();
    };

    MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
    {
    setFixedSize(900, 400);

    QToolButton * mybutton2 = new QToolButton(this);
    mybutton2->setIcon(QIcon("/shihao/qicon/clock.JPG"));
    mybutton2->setText("Sample text");
    mybutton2->setToolButtonStyle(Qt::ToolButtonIconOnly);
    mybutton2->setIconSize(QSize(50,80));
    mybutton2->setGeometry(490, 70, 95, 100);
    mybutton2->setAutoRaise(1);

    mybutton2->setContextMenuPolicy(Qt::ActionsContextMenu);
    connect(mybutton2, SIGNAL(clicked()), this, SLOT(call()));

    }

    void call(){
    AnalogClock clock;
    clock.show();
    }

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    MyWidget widget;
    widget.show();
    //AnalogClock clock;
    //clock.show();
    return app.exec();
    }

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to click and pop up submenu

    a) context menu is only executed for mouse right click button. And where are your actions???
    b) try to use the mentioned setMenu().

  5. The following user says thank you to Lykurg for this useful post:

    shihao (19th March 2010)

  6. #5
    Join Date
    Mar 2010
    Posts
    25
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to click and pop up submenu

    Look at my main program

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    //MyWidget widget;
    //widget.show();
    AnalogClock clock;
    clock.show();
    return app.exec();
    }

    Lets' say I uncomment the Analogclock like above, the clock program are able to display.

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    MyWidget widget;
    widget.show();
    //AnalogClock clock;
    //clock.show();
    return app.exec();
    }

    On the other hand, I uncomment the widget like above code, the menu page able to displayed.
    So my problem is, how to I integrate the menu page with analogclock page, when I click the button of menu page, analogclock only will display.
    Analogclock not really a menu right? setmenu is the correct library to be use?

    Should I place the setmenu(); in the main function?
    I apologize if I ask too silly question, my boss throw the whole qt and ask me to explore alone yet just give me a qt link. I am Headache already....

  7. #6
    Join Date
    Mar 2010
    Posts
    25
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to click and pop up submenu

    hi Lykurg,

    How ? Don't have any solution for me? Come on, just a simple job for you to point up the clue for me...

    Thanks and regards
    Shi Hao

  8. #7
    Join Date
    Mar 2010
    Posts
    25
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to click and pop up submenu

    Or ... is there anywhere pop up a new window by using QPushbutton? Is the QPushbutton able to add pic, adjust pic just like Qtoolbutton?

Similar Threads

  1. Replies: 2
    Last Post: 8th December 2009, 17:33
  2. QMenu: want a QListView in submenu to handle lots of options
    By chezifresh in forum Qt Programming
    Replies: 1
    Last Post: 12th November 2009, 23:55
  3. Context Menu's submenu doesn't appear
    By DancingFirefly in forum Qt Programming
    Replies: 0
    Last Post: 19th August 2009, 20:32
  4. Replies: 1
    Last Post: 23rd July 2008, 10:19
  5. How to show SubMenu next to MainMenu?
    By alex chpenst in forum Qt Programming
    Replies: 4
    Last Post: 17th July 2008, 10:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.