PDA

View Full Version : Adding a QWidget to QToolbar



qtUser500
13th October 2009, 19:54
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.

high_flyer
14th October 2009, 20:59
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.

qtUser500
16th October 2009, 16:15
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.

high_flyer
16th October 2009, 16:21
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.

qtUser500
16th October 2009, 17:30
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.

high_flyer
16th October 2009, 17:35
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....;)

qtUser500
16th October 2009, 19:16
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.