Results 1 to 7 of 7

Thread: Subclass Pushbutton

  1. #1
    Join Date
    Nov 2006
    Posts
    3
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Subclass Pushbutton

    Hi Qt Community,

    I like to right mouse click on a Push Button to select a context menu or popup menu.
    However, I like to left mouse click for the Push Button, using the click() signal.

    This would combine the Push Button and Popup Menu Button into one button, selecting the Pushbutton with the left mouse button and the right mouse button for the Popup Menu Button or context menu.

    Please point me in the right direction, lost.

    Thanks,

    Newbie

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

    Default Re: Subclass Pushbutton

    Quote Originally Posted by Smith View Post
    Hi Qt Community,
    Hi Qt Fan!

    Please point me in the right direction, lost.
    Reimplement QWidget::contextMenuEvent ( QContextMenuEvent * e ).

  3. #3
    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: Subclass Pushbutton

    Hi, have you noticed QPushButton::setPopup()?
    J-P Nurmi

  4. #4
    Join Date
    Nov 2006
    Posts
    3
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Subclass Pushbutton

    Thanks for the advice, I am still struggling.

    The Qt menu example for QWidget::contextMenuEvent ( QContextMenuEvent * e ) has the main window as the parent. If you right mouse click the context menu is display any where on the main window. I would like a context menu for a specific pushbutton. I am unsure how to make the pushbutton the parent of the context window.

    Using the popup option seems to make the button a dedicated popup menu button.

    I am using the example from the Qt Quarterly,

    http://doc.trolltech.com/qq/qq10-signalmapper.html

    Each button pass a integer value to a slot for a QProcess. I would like to add three more slots and connect these slots to a context menu, passing a integer value.

    I really have two problems to resolve, pushbutton context menu and passing integer to the selected slot.

    Thanks for your help,

    Newbie

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

    Default Re: Subclass Pushbutton

    I admit I don't understand what your problem is... QPopupMenu takes a pointer to a widget (any widget) as a parent and you can always pass 0 there, so that's not a problem. The main idea of this approach is to create a QPopupMenu object and call its exec() method to show it on screen at a desired position. I think the example is pretty clear at what needs to be done.

  6. #6
    Join Date
    Nov 2006
    Posts
    3
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Subclass Pushbutton

    Thanks for the advice, I am able to get the popup menus. I use a array of pushbuttons and need to make array of popup menus for this to work. I believe I may need to pass a integer to the contextMenuEvent( QContextMenuEvent * ) function. However, the ContextMenuEvent member does not have any signals which can be used with the connect or signal mapper. Any advice or I am still missing something.

    Newbie

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

    Default Re: Subclass Pushbutton

    I suggest you subclass QPushButton and introduce a method to associate a popup menu with each instance of the button and then use the subclass instead of QPushButton on your forms or widgets. You can use the promotion feature of Designer to insert your subclassed widgets instead of QPushButtons on a Designer form. It'll be much easier this way than using a mapper.

Similar Threads

  1. connecting image to a pushbutton
    By sudheer in forum Qt Tools
    Replies: 2
    Last Post: 4th December 2007, 09:23
  2. QSqlQueryModel write subclass
    By skuda in forum Qt Programming
    Replies: 6
    Last Post: 29th October 2007, 16:18
  3. Replies: 1
    Last Post: 2nd July 2007, 16:29
  4. why pushbutton moving??
    By Shuchi Agrawal in forum Qt Tools
    Replies: 7
    Last Post: 19th January 2007, 17:17
  5. QT4: Sorting in QTreeWidget (subclass)
    By Michiel in forum Qt Programming
    Replies: 21
    Last Post: 29th March 2006, 18:08

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.