Results 1 to 5 of 5

Thread: Custom button

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    25
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Custom button

    Hi!

    There is a question to create button (or action for QToolBar) like this:

    Here is two states: checked and unchecked + menu or other additional action.

    Any ideas?
    PS: sorry, if there exists topic like this...

  2. #2
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom button

    Use QToolButton::setPopupMode(QToolButton::MenuButtonPopup) to get the menu drop down, and QAbstractButton::setCheckable(true) (inherited by QToolButton) to make the button checkable. Then supply both "On" and "Off" images for the QIcon you set on the button.

  3. #3
    Join Date
    Oct 2009
    Posts
    25
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom button

    Yes, I created this: http://paste.org.ru/?nw5bfs But don't know how to create action instead menu
    (really, it's needed to show widget insted menu)

  4. #4
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom button

    Quote Originally Posted by Erik-Moscow View Post
    (really, it's needed to show widget insted menu)
    Perhaps it would work to create a QWidgetAction, then use QMenu::addAction(QAction*) to add it as the single item in a menu, then set that as the menu for the QToolButton.

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

    Erik-Moscow (1st February 2010)

  6. #5
    Join Date
    Oct 2009
    Posts
    25
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom button

    Thanks a lot! Works great! =)
    Working code:
    Qt Code:
    1. #include <QApplication>
    2. #include <QtGui>
    3.  
    4. int main(int argc, char **argv)
    5. {
    6. QApplication app(argc, argv);
    7.  
    8. QSlider *sl = new QSlider(Qt::Horizontal);
    9. sl->setRange(10, 100);
    10. sl->setFixedWidth(200);
    11. sl->setTickPosition(QSlider::TicksBelow);
    12.  
    13. wa->setDefaultWidget(sl);
    14.  
    15. QMenu *menu = new QMenu;
    16. menu->addAction(wa);
    17.  
    18. btn.setText("Checkable");
    19. btn.setMenu(menu);
    20. btn.setPopupMode(QToolButton::MenuButtonPopup);
    21. btn.setCheckable(true);
    22.  
    23. btn.show();
    24.  
    25. return app.exec();
    26. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Custom Button
    By wirasto in forum Newbie
    Replies: 1
    Last Post: 14th November 2009, 10:59
  2. Custom widget: a button within a button
    By Gnurou in forum Qt Programming
    Replies: 7
    Last Post: 18th June 2009, 09:03
  3. Connect Button to a custom slot
    By Majestade in forum Qt Programming
    Replies: 2
    Last Post: 28th March 2007, 17:17
  4. How to create a custom Button?
    By Mister_Crac in forum Qt Programming
    Replies: 18
    Last Post: 22nd October 2006, 23:59
  5. custom maximize button---
    By Naveen in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2006, 13:11

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.