KTitleWidget and the native Mac style
René J.V. Bertin
rjvbertin at gmail.com
Tue Jul 4 21:13:24 UTC 2017
On Tuesday July 04 2017 20:16:55 Sebastian Kügler wrote:
@Kevin: should we continue to CC you?
> The frame in my understanding is old weight, and can go (do check with the VDG
> though!)
Thing is that you cannot simply get rid of the QFrame, it would at least have to be replaced with something invisible that can take over its other role.
What works (mostly) is something like this:
KTitleWidget::KTitleWidget(QWidget *parent)
: QWidget(parent),
d(new Private(this))
{
QFrame *titleFrame = new QFrame(this);
// titleFrame->setAutoFillBackground(true);
// titleFrame->setFrameShape(QFrame::StyledPanel);
titleFrame->setFrameShadow(QFrame::Plain);
// titleFrame->setBackgroundRole(QPalette::Base);
// default image / text part start
d->headerLayout = new QGridLayout(titleFrame);
d->headerLayout->setColumnStretch(0, 1);
// d->headerLayout->setMargin(6);
d->headerLayout->setContentsMargins(0, 0, 0, 0);
//...
}
and replace `d->textLabel->setStyleSheet(d->textStyleSheet())` with
d->textLabel->setFont(QFontDatabase::systemFont(QFontDatabase::TitleFont));
(that will use the window titlebar font, but also when no platform theme plugin -aka plasma-integration- is installed).
in Breeze we can then do
} else if( qobject_cast<QFrame*>( widget ) && widget->parent() && widget->parent()->inherits( "KTitleWidget" ) ) {
QFrame *frame = qobject_cast<QFrame*>( widget );
if( StyleConfigData::titleWidgetDrawFrame() ) {
frame->setAutoFillBackground( true );
frame->setFrameShape( QFrame::StyledPanel );
frame->setBackgroundRole( QPalette::Base );
// make the title frame a bit less luxuriously big, and centre the text vertically
frame->layout()->setContentsMargins(3, 3, 3, 0);
} else {
frame->setAutoFillBackground( false );
frame->setFrameShape( QFrame::NoFrame );
frame->setBackgroundRole( QPalette::Window );
// don't take extra space for a frame we're not showing at all
frame->layout()->setContentsMargins(0, 0, 0, 0);
}
}
There is 1 difference that I do not yet understand: when done like this, the frame background fill is slightly larger than the outline. Or maybe it's the outline that is drawn with rounded corners and thus slightly smaller. The effect is akin to an etched bevel. Not very striking with my palette or the Breeze palette, more so with other palettes.
In fact, what I don't understand why rounded corners aren't used all the time; they're hardcoded (in Helper::renderFrame).
R.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: breeze-title-framed.png
Type: image/png
Size: 28613 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20170704/df6253cf/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: breeze-title-noframe.png
Type: image/png
Size: 28626 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20170704/df6253cf/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: macintosh-title.png
Type: image/png
Size: 27858 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20170704/df6253cf/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qtcurve-title.png
Type: image/png
Size: 27024 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20170704/df6253cf/attachment-0007.png>
More information about the Kde-frameworks-devel
mailing list