Results 1 to 10 of 10

Thread: button question

  1. #1
    Join Date
    Feb 2007
    Posts
    42
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question button question

    hi, i want to create a button that when pressed it will display a context menu...

    is there any widget that will do this, off the shelf?

    is it easy to implement it by myself?

    thanks for your time,

    NA

  2. #2
    Join Date
    Dec 2006
    Location
    Wuhan, China
    Posts
    14
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: button question

    You can use QContextMenuEvent.

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: button question

    is there any widget that will do this, off the shelf?
    Yes - QPushButton
    Connect the clicked() signal to a slot, in that slot emit a QContextMenuEvent.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: button question

    How about using QToolButton? It supports a menu with three different popup styles, out of the box.
    J-P Nurmi

  5. #5
    Join Date
    Feb 2007
    Posts
    42
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: button question

    Quote Originally Posted by high_flyer View Post
    Yes - QPushButton
    Connect the clicked() signal to a slot, in that slot emit a QContextMenuEvent.
    any guide on how to do this?

  6. #6
    Join Date
    Feb 2007
    Posts
    42
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: button question

    also any guide on how to do this?

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: button question

    I gave you the 'guide', what more do you need?
    1. create a slot
    2. connect the clicked() signal to that slot
    3. in the slot emit the event

  8. #8
    Join Date
    Feb 2007
    Posts
    42
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: button question

    Quote Originally Posted by high_flyer View Post
    I gave you the 'guide', what more do you need?
    1. create a slot
    2. connect the clicked() signal to that slot
    3. in the slot emit the event
    in the book c++ gui programming with qt4 i found another way{create an action, populate a menu, connect the menu with button}


    Qt Code:
    1. oneAction= new QAction("do something!!", this);
    2. connect(oneAction, SIGNAL(triggered()), this, SLOT(action()));
    3. processMenu->addAction(oneAction);
    4. menuButton->setMenu(&processMenu);
    To copy to clipboard, switch view to plain text mode 

    what is the difference? between these 2 ways?
    Last edited by aegis; 31st March 2007 at 19:29.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: button question

    That's exactly the same what Jpn suggested.

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: button question

    what is the difference? between these 2 ways?
    The method from the book that Jpn suggested uses QActions and signals.
    I find it also better, so use it.
    The other method is using an event, which probably is what happens with the signal method behind the scenes.

Similar Threads

  1. Disable Checkable Button Question
    By jbpvr in forum Qt Programming
    Replies: 9
    Last Post: 20th March 2007, 17:57
  2. Mouse Over event on button
    By vishal.chauhan in forum Qt Programming
    Replies: 9
    Last Post: 10th January 2007, 05:03
  3. Button with signals and slots
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 4th December 2006, 22:24
  4. Push button double click
    By curtisw in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2006, 16:40
  5. QLabel on a Button
    By cwalsh in forum Newbie
    Replies: 4
    Last Post: 12th January 2006, 16:06

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.