Search code examples
user-interfaceqtqt4color-picker

How could I use the QColorDialog inside another widget not as a separate dialog?


I would like to use QColorDialog not as a dialog window but as a widget which I could insert into a layout. (More specifically as a custom sub menu in a context menu)

I looked into the QColorDialog sourcecode, and I could probably copy over a part of the internal implementation of the QColorDialog to achieve this, but is there a cleaner way to do this? I am using Qt 4.5.1...


Solution

  • If there's a way to do this cleanly, I'm not aware of it. As I see it, you have a couple of options:

    • Subclass it and copy the code that actually constructs the widget, making edits to remove the part that creates the dialog window and replace it with some other container.
    • If you're not dead-set on using that particular dialog, the color triangle widget from qt solutions might work, because it isn't a dialog window. You can find it at http:// doc.trolltech.com/solutions/4/qtcolortriangle/qtcolortriangle.html (remove the space from the link)