Results 1 to 7 of 7

Thread: Adding a QWidget to QToolbar

  1. #1
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Adding a QWidget to QToolbar

    Hi,

    I am using QT4 and would like to know how, from Qt Designer, I can add a QWidget to the toolbar. I specifically would like to add a QActionGroup, QLineEdit and QLabel.

    I added the QToolbar in the Designer, and tried to drag and drop the widget from the Widget box list but it is not possible. I am able to add other actions that I create through the Action Editor though.

    Any pointers would be appreciated.
    Thanks.

  2. #2
    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: Adding a QWidget to QToolbar

    Is you QToolBar a child of a QMainWindow?
    If not then (from the documentation):
    When a QToolBar is not a child of a QMainWindow, it looses the ability to populate the extension pop up with widgets added to the toolbar using addWidget(). Please use widget actions created by inheriting QWidgetAction and implementing QWidgetAction::createWidget() instead. This is a known issue which will be fixed in a future release.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Adding a QWidget to QToolbar

    Thanks high_flyer for the information.

    But what I can't understand is I have a 3.3.5 version of this application, where I can see the QToolbar has a QLinEdit, QActionGroup etc added to it. I am trying to port this application to QT4. The older application was done long ago by someone else, so I don't know how they accomplished it. I am playing around with the options to see if there is a certain method through which I can add it.

    I have attached what my current Object Inspector looks like with the QToolBar added to the QMainWindow (so I assume it is a child of QMainWindow)

    Any suggestions or links to documentation are welcome.
    Thanks.
    Attached Images Attached Images

  4. #4
    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: Adding a QWidget to QToolbar

    The move to Qt4 changed Qt in a very dramatic way.
    Things don't work the same under the hood in many things between Qt3 and Qt4.

    But the quotation I gave you tells you how to do what you want:
    Please use widget actions created by inheriting QWidgetAction and implementing QWidgetAction::createWidget() instead. This is a known issue which will be fixed in a future release.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Adding a QWidget to QToolbar

    Thanks high_flyer.

    I located the quotation for QToolbar in the Qt Assistant. And as you quoted in your first comment, the 'known issue' is ONLY for having the pop-up extension populate widgets.

    In my case I want to add these QWidgets (QLineEdit etc) in the Designer.
    It can be added in the code using 'InsertWidget' to add the QLineEdit in a specific location on the toolbar. But was curious to know how this can be done through the designer or Qt4.5.1

    I am sorry if my question was mis-understood, but it was nice of you to reply with your inputs.
    Thanks.

  6. #6
    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: Adding a QWidget to QToolbar

    I see - no the fault is mine, I read the post too fast, and didn't get it that you are trying to add it exclusively through designer.

    You have to use code some times you know....
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Adding a QWidget to QToolbar

    Hmm .. I guess I will have to add them thru the code then.

    I would have thought QT had the option to do so from Designer, especially since QT 3.3.5 had this option!
    I wish QT brings back this feature, as it is good to have all the GUI components visible at the designing phase itself.

Similar Threads

  1. Adding a scrollbar to a QWidget
    By qtUser500 in forum Newbie
    Replies: 13
    Last Post: 2nd September 2009, 19:48
  2. QGraphicsView and adding QWidget with transparent areas
    By sting73 in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2009, 11:19
  3. Replies: 11
    Last Post: 25th February 2009, 17:35
  4. how to add QWidget to QToolBar
    By babu198649 in forum Qt Tools
    Replies: 2
    Last Post: 22nd September 2008, 06:58
  5. Dynamic updates of a QWidget in a QScrollArea
    By plamkata in forum Qt Programming
    Replies: 2
    Last Post: 20th July 2008, 23:45

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.