PDA

View Full Version : Creating a popup toolbox



Jachyra
17th February 2007, 22:01
I'm new to Qt so I thought I would start off with trying to create something simple.

What I'm trying to do is create a popup toolbox that can be used anywhere that a context menu might be used. But I can already envision the compiler messages being generated if I don't inherit from the proper classes. So my question, for those OO programmers out there who are way better at this stuff than I am, is what classes do I want to inherit from, QToolbox or QMenu....or both? And is there any way that I'm going to be able to send in any kind of custom widget to a method that is expecting a " QMenu* " as its parameter?

Also, I'm not looking to reinvent the wheel, so if anyone has a link to something like this thats already been done, it would be great if you'd be willing to share it.

Thanks in advance for any responses.

wysota
17th February 2007, 23:04
I'm not sure what you're exactly trying to do, but if it's only a set of menu options to choose from then you don't need to inherit anything. Just create a QMenu (of course you can inherit it as well, that's your choice) and add actions to it using addAction() method (there are few variants of that method, the simplest taking a QAction*).

Jachyra
18th February 2007, 01:34
No, thats not what I'm trying to do. What I'm trying to do is to create a context menu that is actually a QToolbox....so that instead of having your typical sub-menus like you would with a standard QMenu, you have collapsible sections.

wysota
18th February 2007, 03:00
Ok, I understand now. You need to subclass QMenu then. You may then try to embed a QToolBox inside it (by a parent-child relation, not by inheritance - you can't inherit from both QMenu and QToolBox as they both inherit QObject and multiple inheritance of QObject is not allowed).

Jachyra
18th February 2007, 04:28
Not really sure how to approach "embedding" it. Could it be as easy as just calling "setParent"?

wysota
18th February 2007, 11:23
MyMenu::MyMenu(...) : QMenu(...){
QVBoxLayout *l = new QVBoxLayout(this);
QToolBox *tb = new QToolBox;
l->addWidget(tb);
//...
}