{
titleOption.initFrom( this );
titleOption.text = "Custom PopUp";
titleOption.rect = rect();
titleOption.rect.setHeight( 23 );
titleOption.titleBarState = (int)Qt::WindowActive | ~Qt::WindowMinimized;
painter.
drawComplexControl( QStyle::CC_TitleBar, titleOption
);
frameOption.initFrom( this );
frameOption.
rect = QRect( rect
().
x(), rect
().
y() + 23, rect
().
width(), rect
().
height() - 23 );
painter.
drawPrimitive( QStyle::PE_Frame, frameOption
);
QIcon icon
= style
()->standardIcon
( QStyle::SP_DialogCloseButton );
painter.drawItemPixmap( r, (int)Qt::AlignRight | Qt::AlignVCenter, icon.pixmap( 19, 19 ) );
r
= QRect( 0,
0, rect
().
width(),
23 );
QFont f
= painter.
font();
f.setBold( true );
painter.setFont( f );
painter.
drawItemText( r,
(int)Qt
::AlignHCenter | Qt
::AlignVCenter, tPalette,
true,
"Custom PopUp",
QPalette::WindowText );
}
void CustomPopUp::paintEvent( QPaintEvent* event )
{
QWidget::paintEvent( event );
QStylePainter painter( this );
QPalette tPalette = palette();
tPalette.setColor( QPalette::WindowText, QColor( Qt::white ) );
QStyleOptionTitleBar titleOption;
titleOption.initFrom( this );
titleOption.text = "Custom PopUp";
titleOption.rect = rect();
titleOption.rect.setHeight( 23 );
titleOption.titleBarState = (int)Qt::WindowActive | ~Qt::WindowMinimized;
painter.drawComplexControl( QStyle::CC_TitleBar, titleOption );
QStyleOptionFrame frameOption;
frameOption.initFrom( this );
frameOption.rect = QRect( rect().x(), rect().y() + 23, rect().width(), rect().height() - 23 );
painter.drawPrimitive( QStyle::PE_Frame, frameOption );
QIcon icon = style()->standardIcon( QStyle::SP_DialogCloseButton );
QRect r = QRect( 0, 0, rect().width() - 5, 23 );
painter.drawItemPixmap( r, (int)Qt::AlignRight | Qt::AlignVCenter, icon.pixmap( 19, 19 ) );
r = QRect( 0, 0, rect().width(), 23 );
QFont f = painter.font();
f.setBold( true );
painter.setFont( f );
painter.drawItemText( r, (int)Qt::AlignHCenter | Qt::AlignVCenter, tPalette, true, "Custom PopUp", QPalette::WindowText );
}
To copy to clipboard, switch view to plain text mode
Bookmarks