fix: statusbar at some rare conditions crash

the stacktrace show the line is parentWidget().
avoid using this the parentWidget() method.
This commit is contained in:
YiFang Xiao 2023-07-01 22:33:58 +08:00
parent 6deb38be7b
commit ed8072d78f

View file

@ -40,6 +40,9 @@ MainStatusBar::MainStatusBar( QWidget *parent ) : QWidget( parent )
connect( timer, &QTimer::timeout, this, &MainStatusBar::clearMessage ); connect( timer, &QTimer::timeout, this, &MainStatusBar::clearMessage );
setAutoFillBackground( true ); setAutoFillBackground( true );
if ( parent )
move( 0, parent->height() - height() );
} }
void MainStatusBar::clearMessage() void MainStatusBar::clearMessage()
@ -67,29 +70,23 @@ void MainStatusBar::setBackgroundMessage(const QString & bkg_message )
} }
} }
void MainStatusBar::showMessage(const QString & str, int timeout, const QPixmap & pixmap) void MainStatusBar::showMessage( const QString & str, int timeout, const QPixmap & pixmap )
{ {
textWidget->setText( message = str ); textWidget->setText( message = str );
picWidget->setPixmap( pixmap ); picWidget->setPixmap( pixmap );
if ( !picWidget->pixmap().isNull() ) if ( !picWidget->pixmap().isNull() ) {
{
picWidget->setFixedSize( textWidget->height(), textWidget->height() ); picWidget->setFixedSize( textWidget->height(), textWidget->height() );
} }
else else {
{
picWidget->setFixedSize( 0, 0 ); picWidget->setFixedSize( 0, 0 );
} }
if ( timeout > 0 ) if ( timeout > 0 ) {
{
timer->start( timeout ); timer->start( timeout );
} }
if ( parentWidget() && parentWidget()->isVisible() ) { raise();
raise(); show();
show();
move( QPoint( 0, parentWidget()->height() - height() ) );
}
} }
void MainStatusBar::mousePressEvent ( QMouseEvent * ) void MainStatusBar::mousePressEvent ( QMouseEvent * )