Results 1 to 6 of 6

Thread: QPushButton and QToolButoon in QToolBar

  1. #1
    Join Date
    Mar 2013
    Posts
    43
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    2

    Default QPushButton and QToolButoon in QToolBar

    Hi,
    How to add QPushButton and QToolButton in QToolBar in ui. Please help me

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: QPushButton and QToolButoon in QToolBar

    Right-click on the main window and select Add toolbar from the context menu.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Mar 2013
    Posts
    43
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    2

    Default Re: QPushButton and QToolButoon in QToolBar

    I am having Toolbar. I want to add QPushButton and QToolButton on ToolBar

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: QPushButton and QToolButoon in QToolBar

    From UI designer it is not possible, from code you will need to use QWidgetAction
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    Mar 2013
    Posts
    43
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    2

    Default Re: QPushButton and QToolButoon in QToolBar

    Thank u very much....
    Can u give an example

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: QPushButton and QToolButoon in QToolBar

    Just one example
    QToolBar.jpg
    Qt Code:
    1. #include <QtGui>
    2. #include <QApplication>
    3.  
    4. class PushButtonAction : public QWidgetAction
    5. {
    6. public:
    7. explicit PushButtonAction(const QIcon & icon, const QString & text, QObject *parent = 0)
    8. : QWidgetAction(parent)
    9. {
    10. setIcon(icon);
    11. setObjectName(text);
    12. }
    13.  
    14. protected:
    15. virtual QWidget * createWidget(QWidget * parent)
    16. {
    17. return new QPushButton(icon(), objectName(), parent);
    18. }
    19.  
    20. virtual void deleteWidget(QWidget * widget)
    21. {
    22. delete widget;
    23. }
    24. };
    25.  
    26. int main(int argc, char **argv)
    27. {
    28. QApplication app(argc, argv);
    29.  
    30. QMainWindow mainWindow;
    31.  
    32. QToolBar * toolBar= new QToolBar("Main Window Tool Bar");
    33. toolBar->insertAction(0, new PushButtonAction(QIcon(":/Refresh.gif"), "Refresh"));
    34. toolBar->addAction(QIcon(":/First.gif"), "FirstAction");
    35. toolBar->addAction(QIcon(":/Last.gif"), "LastAction");
    36. toolBar->insertAction(0, new PushButtonAction(QIcon(":/Search.gif"), "Search"));
    37.  
    38. mainWindow.addToolBar(Qt::TopToolBarArea, toolBar);
    39. mainWindow.showMaximized();
    40.  
    41. return app.exec();
    42. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Replies: 0
    Last Post: 22nd February 2010, 10:30
  2. QToolBar
    By Programm3r in forum Qt Programming
    Replies: 2
    Last Post: 22nd December 2009, 08:09
  3. QToolBar help
    By Erlendhg in forum Qt Programming
    Replies: 2
    Last Post: 6th November 2006, 16:20
  4. Replies: 3
    Last Post: 26th September 2006, 13:16
  5. QToolBar help please
    By munna in forum Qt Programming
    Replies: 3
    Last Post: 29th June 2006, 18:18

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.