{
Q_UNUSED(event)
QStyle* style
= this
->style
();
QRect active_area
= this
->rect
();
qDebug() << active_area;
int titlebar_height = 0;
// Titlebar.
t_opt.initFrom(this);
titlebar_height
= style
->pixelMetric
(QStyle::PM_TitleBarHeight,
&t_opt,
this);
qDebug() << titlebar_height;
t_opt.
rect = QRect(0,
0, this
->width
(), titlebar_height
);
t_opt.titleBarState = this->windowState();
t_opt.titleBarFlags = Qt::FramelessWindowHint;
t_opt.text = t_opt.fontMetrics.elidedText(this->windowTitle(), Qt::ElideRight, t_opt.rect.width());
style
->drawComplexControl
(QStyle::CC_TitleBar,
&t_opt,
&painter,
this);
style
->drawItemText
(&painter, t_opt.
rect, Qt
::AlignCenter, t_opt.
palette,
true, t_opt.
text,
QPalette::ToolTipText);
// Background widget.
active_area.
setTopLeft(QPoint(0, titlebar_height
));
this->setContentsMargins(0, titlebar_height, 0, 0);
w_opt.initFrom(this);
w_opt.rect = active_area;
qDebug() << w_opt.rect;
style
->drawPrimitive
(QStyle::PE_Widget,
&w_opt,
&painter,
this);
}
void customDlg::paintEvent(QPaintEvent* event)
{
Q_UNUSED(event)
QPainter painter(this);
QStyle* style = this->style();
QRect active_area = this->rect();
qDebug() << active_area;
int titlebar_height = 0;
// Titlebar.
QStyleOptionTitleBar t_opt;
t_opt.initFrom(this);
titlebar_height = style->pixelMetric(QStyle::PM_TitleBarHeight, &t_opt, this);
qDebug() << titlebar_height;
t_opt.rect = QRect(0, 0, this->width(), titlebar_height);
t_opt.titleBarState = this->windowState();
t_opt.titleBarFlags = Qt::FramelessWindowHint;
t_opt.text = t_opt.fontMetrics.elidedText(this->windowTitle(), Qt::ElideRight, t_opt.rect.width());
style->drawComplexControl(QStyle::CC_TitleBar, &t_opt, &painter, this);
style->drawItemText(&painter, t_opt.rect, Qt::AlignCenter, t_opt.palette, true, t_opt.text, QPalette::ToolTipText);
// Background widget.
active_area.setTopLeft(QPoint(0, titlebar_height));
this->setContentsMargins(0, titlebar_height, 0, 0);
QStyleOption w_opt;
w_opt.initFrom(this);
w_opt.rect = active_area;
qDebug() << w_opt.rect;
style->drawPrimitive(QStyle::PE_Widget, &w_opt, &painter, this);
}
To copy to clipboard, switch view to plain text mode
but there is a gray rect behind the round corner of the titlebar(see attachment), how can i remove(or hide) it?
Bookmarks