4

I'm trying to find a signal to know when a qwidget is visible or not, I mean, when a QWidget is at the top of the desktop or when it's hide under some window.

I also would like to know with a signal when a QWidget window is minimized and when it's restored (un-minimized). I have tried the next code, but when I minimize my window, the window closes and is not in the applications bar.

void KGLWidget::changeEvent(QEvent *event) {
        if (event->type() == QEvent::WindowStateChange) {
            if (isMinimized() || !isVisible()) {
                emit onHide();
                event->ignore();
                qDebug() << "NO SE VE";
                return;
            }
            if(isVisible()) {
                emit onShow();
                event->ignore();
                qDebug() << "SI SE VE";
                return;
            }

        }

    QWidget::changeEvent(event);
    }

I also tried with event->accept(), also without event->ignore() and without return; but the qwidget window always closes.

Thank you very much, I really appreciate your time and your help.

Thanks in advance.

Chris
  • 17,119
  • 5
  • 57
  • 60
Hermandroid
  • 2,120
  • 4
  • 29
  • 35

1 Answers1

1

Does you say the window close mean that the program quit? The code what you shown will not cause the program to quit. Maybe you do something make the program quit in the slot which connect to the signal onHide() and onShow().

If you just want to do something when the widget show and hide, you can try to reimplement these two event handler

void QWidget::showEvent ( QShowEvent * event )   [virtual protected]
void QWidget::hideEvent ( QHideEvent * event )   [virtual protected]
liuyi.luo
  • 1,219
  • 7
  • 11