PDA

View Full Version : Promoting widget in Designer



evident
24th July 2010, 21:27
Hi everybody,

I am working on a project for which I have designed the user interface in the Designer.

I now want to add a too bar above my QGraphicsView. For this I would like to use QToolBar.

Unfortunately I can't add a QToolBar directly in the designer, so I just added a "Widget" where I want the toolbar to be placed. I then created a class "ToolBar2D", which inherits from QToolBar.

Now I have found out that I can promote widgets to user-defined classes. So I right-clicked the Widget in the designer and clicked on "Promote to..."

Then a window opened where I tried to add the class:

Base-Class: QToolBar
Class-name: ToolBar2D
Include-File: toolbar2d.h
Global include file: checked

I can then click the button to add this class, but the "Promote" button is disabled. And in the list above the class is added but it says "not used"

(all the terms I wrote were translated since my Designer is in German)...

Can anybody tell me why this isn't working? Why is the added class not accepted?

Would be great if anyone could help me!

Thanks,
-evident-

Lykurg
24th July 2010, 21:32
In the designer you have inserted a QWidget, so you can only promote classes which have QWidget as base. So simply tell designer QWidget is the base class of your ToolBar2D.

evident
24th July 2010, 21:57
Ahh ok thank you... This of course makes sense! Working...

wysota
24th July 2010, 22:36
Or better yet put your graphics view into QMainWindow and use the regular toolbar features from Designer.

evident
24th July 2010, 22:38
Well since I don't just have the QGraphicsView and the toolbar this won't work... there are two Toolbars, one for the QGraphicsView below and one for a QGLWidget... and there also is other stuff.... but thanks for the tip...

wysota
24th July 2010, 23:06
Well since I don't just have the QGraphicsView and the toolbar this won't work...
Sure it will. If you want, you can always place a QMainWindow into another widget. If you use a plain QToolBar without a QMainWindow (I sometimes do that as well), it has its down sides, like not being able to move toolbars around, closing them, etc.