Problem with the Improved StatusbarProgressWidget
René J.V. Bertin
rjvbertin at gmail.com
Sat Oct 29 20:30:26 UTC 2016
Hi Anton,
How good are you in getting widgets to show up exactly where you want them, and understand why they don't if they don't?
I've been working on this annoying little issue, thinking I'd be clever and use another QToolButton as the placeholder instead of an empty QLabel, for when the progress widget is supposed to be hidden. The final implementation would of course use an invisible button, but for now I'm doing this:
```
if (m_bShowButton) {
m_pPlaceHolder.button = new QToolButton(this);
m_pPlaceHolder.button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed,
QSizePolicy::Fixed ) );
m_pPlaceHolder.button->setIcon(smallIcon);
m_pPlaceHolder.button->setIconSize( iconSize );
m_pPlaceHolder.button->setMinimumSize(m_pButton->minimumSizeHint());
m_pPlaceHolder.button->setAutoRaise(true);
m_pPlaceHolder.button->setAttribute( Qt::WA_LayoutUsesWidgetRect, true );
// m_pPlaceHolder.button->setEnabled(false);
m_pPlaceHolder.button->installEventFilter( this );
stack->insertWidget( 2, m_pPlaceHolder.button );
m_pPlaceHolder.button->hide();
} else {
m_pPlaceHolder.label = new QLabel( QString(), this );
m_pPlaceHolder.label->setSizePolicy( QSizePolicy( QSizePolicy::Fixed,
QSizePolicy::Fixed ) );
m_pPlaceHolder.label->setAlignment( Qt::AlignHCenter );
m_pPlaceHolder.label->installEventFilter( this );
m_pPlaceHolder.label->setMinimumWidth( w );
m_pPlaceHolder.label->setMaximumHeight( maximumHeight );
stack->insertWidget( 2, m_pPlaceHolder.label );
}
```
and
```
void StatusbarProgressWidget::setMode() {
switch ( mode ) {
case None:
if ( m_bShowButton ) {
m_pButton->hide();
m_pPlaceHolder.button->show();
// show the empty button in order to make the status bar look better
stack->setCurrentWidget( m_pPlaceHolder.button );
} else {
// show the empty label in order to make the status bar look better
stack->setCurrentWidget( m_pPlaceHolder.label );
}
m_pProgressBar->hide();
stack->show();
#ifdef Q_OS_OSX
MacDockProgressView::setProgressVisible( false );
#endif
break;
case Progress:
stack->show();
m_pProgressBar->show();
stack->setCurrentWidget( m_pProgressBar );
if ( m_bShowButton ) {
m_pButton->show();
m_pPlaceHolder.button->hide();
}
#ifdef Q_OS_OSX
MacDockProgressView::setProgressVisible( true );
#endif
break;
}
}
```
I think the result shows what's going wrong: the placeholder button is drawn with its lower outline coinciding with the statusbar botton, i.e. there's a vertical alignment issue.
I have no good explanation why that would be the case.
The button also gets the same width as the progressbar, despite the fixed size policy - another mystery to me.
A "Didget" all right (cf. the typo in my commit message) :-/
R.
More information about the KDevelop-devel
mailing list