I implemented a color Picker Menu, based on BlackDal ColorPicker
In order to send a signal, when a color has been selected, i added:
class RColorPicker : public QPushButton
{
Q_OBJECT
signals:
void selected( QColor color);
...
and
void RColorPicker::on_popup_selected( QColor color )
{
_selectedColor = color;
repaint();
emit selected( color );
Sowewhere else i connect to that signal like
fillColorButton = new RColorPicker()
connect(fillColorButton , SIGNAL(selected(QColor)), this, SLOT(fillColorButtonTriggered(QColor)) );
This works, when a color is selected from the PopUpMenu, but if i choose "More..." in the PopUp and then select a color from the called QColorDialog
, the connected slot fillColorButtonTriggered
is not called. Instaed, in my MDI-Application a different document becomes the active window. Although it should:
void RColorPickerPopup::mousePressEvent ( QMouseEvent *event )
{
...
QColorDialog *dialog = new QColorDialog( this );
if( dialog->exec() )
{
hoverColor = dialog->selectedColor();
delete dialog;
emit selected( hoverColor );
this->close();
The Problem does not occur, if i replace the QColorDialog
by a native windows ChooseColor
dialog.
Does anybody have a hint, what the problem is here?
I finally found the answer myself: The problem is, that the Qt MDI Sample, that i used, had a function like this:
The Problem is that
(see Qt Documentation)
Obviously as soon as i display a modal Qt Dialog, no MDI Child Window does have focus any more - if i use a native Windows Dialog this seems not to be the case. When i try to set the color of selected elements i called MainWin::activeMdiChild which returns NULL if a Qt Dialog is on top (Yes, i should have checked for returning NULL, which was unexpected at this point).
The solution was, to replace activeSubWindow with currentSubWindow.