views:

623

answers:

4

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

A: 

Try subclassing QColorDialog

PiedPiper
+2  A: 

You might want to look at some Qt Solutions, which will do at least part of what you want. For example, see the Color Picker solution, which they note is now available as an LGPL-licensed library also.

As an alternative (and probably less-supported) approach, I recall some work in the Qt-Labs about embedding Qt widgets, including QDialogs, into a QGraphicsScene. You could potentially do so, then change the view on your graphics scene so that only the portion of the color picker dialog you are interested in was visible to the user. It sounds very hackish, however.

Caleb Huitt - cjhuitt
+2  A: 

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)
Lendrick
A: 

Use QGraphicsView and add QDialog to it and add QGraphicsView to the widget you want to show the dialog.

Suresh