{
QImage *icon
= ( m_target
->isVisible
() ?
&m_icnCollapse
: &m_icnExpand
);
painter.eraseRect( event->rect() );
QSize ts
= painter.
fontMetrics().
size( Qt
::TextShowMnemonic, m_label,
0,
NULL );
painter.drawImage( 7, ( size().height() - icon->size().height() ) / 2, *icon );
painter.
drawText( QRect( QPoint( icon
->size
().
width() + 10,
( size
().
height() - ts.
height() ) / 2 ), ts
), m_label
);
if ( hasFocus() ) {
QVector<qreal> dashes;
dashes << 1 << 2 << 1 << 2 << 1 << 2 << 1 << 2 << 1 << 2;
pen.setColor( painter.pen().color() );
pen.setStyle( Qt::CustomDashLine );
pen.setDashPattern( dashes );
pen.setCapStyle( Qt::RoundCap );
painter.setPen( pen );
painter.drawRect( 2, 2, size().width() - 5, size().height() - 5 );
}
}
void CWidgetHandle::paintEvent( QPaintEvent *event )
{
QPainter painter( this );
QImage *icon = ( m_target->isVisible() ? &m_icnCollapse : &m_icnExpand );
painter.eraseRect( event->rect() );
QSize ts = painter.fontMetrics().size( Qt::TextShowMnemonic, m_label, 0, NULL );
painter.drawImage( 7, ( size().height() - icon->size().height() ) / 2, *icon );
painter.drawText( QRect( QPoint( icon->size().width() + 10, ( size().height() - ts.height() ) / 2 ), ts ), m_label );
if ( hasFocus() ) {
QVector<qreal> dashes;
QPen pen;
dashes << 1 << 2 << 1 << 2 << 1 << 2 << 1 << 2 << 1 << 2;
pen.setColor( painter.pen().color() );
pen.setStyle( Qt::CustomDashLine );
pen.setDashPattern( dashes );
pen.setCapStyle( Qt::RoundCap );
painter.setPen( pen );
painter.drawRect( 2, 2, size().width() - 5, size().height() - 5 );
}
}
To copy to clipboard, switch view to plain text mode
The question I have is about proper drawing in the case of focused handles. Obviously the code as it stands now will only generate good looking visuals in only some cases. For exemplification this is how the test application looks while running under Gnome:
Bookmarks