Results 1 to 6 of 6

Thread: Creating a popup toolbox

  1. #1
    Join Date
    Feb 2007
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Creating a popup toolbox

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Creating a popup toolbox

    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*).

  3. #3
    Join Date
    Feb 2007
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Creating a popup toolbox

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Creating a popup toolbox

    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).

  5. #5
    Join Date
    Feb 2007
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Creating a popup toolbox

    Not really sure how to approach "embedding" it. Could it be as easy as just calling "setParent"?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Creating a popup toolbox

    Qt Code:
    1. MyMenu::MyMenu(...) : QMenu(...){
    2. QVBoxLayout *l = new QVBoxLayout(this);
    3. QToolBox *tb = new QToolBox;
    4. l->addWidget(tb);
    5. //...
    6. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Popup menu for a QGraphicsItem?
    By Morea in forum Qt Programming
    Replies: 4
    Last Post: 4th February 2009, 21:27
  2. Replies: 1
    Last Post: 5th November 2006, 23:50
  3. put a toolbox
    By mickey in forum Newbie
    Replies: 4
    Last Post: 27th August 2006, 15:35
  4. Can't close my popup
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 11th July 2006, 09:10
  5. Problem in creating thread in GUI application
    By jyoti kumar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2006, 12:05

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.