1
votes

I need to handle an event that is fired after widget is fully visible like after show event. But I cannot find any event like that in Qt4. I already tried the solutions suggested below. But none of them worked.

My aim: I am working on an embedded system and I am using Qt for UI. What I am trying to do is to show hardware accelerated camera on UI after CustomWidget is shown. If I use showEvent, camera is shown before CustomWidget is fully drawn. It seems that showEvent is fired before widget is fully drawn. It behaves like before show event.

Failure-1

bool CustomWidget::event(QEvent *event)
{
   bool returnValue = QWidget::event(event);
   if (event->type() == QEvent::Polish)
   {
       this->camera->show();
   }
   return returnValue;
}

Polish event is called once. When I hide and show the widget again and again, it never fired.

Failure-2

void CustomWidget::showEvent(QShowEvent *event)
{
    QWidget::showEvent(event);
    QTimer::singleShot(0, this, SLOT(dialogExec));
}

void CustomWidget::dialogExec()
{
    this->camera->show();
}

This did not work either.

Failure-3

void CustomWidget::paintEvent( QPaintEvent *event )
{
   QWidget::paintEvent( event );

   if( !this->camera->isVisible() )
   {
       this->camera->show();
   }
}

void CustomWidget::hideEvent( QHideEvent *event )
{
   this->camera->hide();
}
1

1 Answers

0
votes

QWidget has protected members called closeEvent( QCloseEvent* event ) and showEvent( QShowEvent* event ). Maybe you can use these methods to manage the camera.