Whats wrong with this QT Signal in my PopUp?

507 views Asked by At

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?

1

There are 1 answers

0
RED SOFT ADAIR On BEST ANSWER

I finally found the answer myself: The problem is, that the Qt MDI Sample, that i used, had a function like this:

MdiChild *MainWin::activeMdiChild()
{
    if (QMdiSubWindow *activeSubWindow = mdiArea->activeSubWindow())
        return qobject_cast<MdiChild *>(activeSubWindow);
    return 0;
}

The Problem is that

if a widget outside the MDI area is the active window, no subwindow will be active

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

MdiChild *MainWin::activeMdiChild()
{
    if (QMdiSubWindow *activeSubWindow = mdiArea->currentSubWindow())
        return qobject_cast<MdiChild *>(activeSubWindow);
    return 0;
}