Hi
How to apply stylesheet to QDialog Title Bar?
Printable View
Hi
How to apply stylesheet to QDialog Title Bar?
You cant do it, using style sheet. Use QStyle instead.
You must create a custom class which inherits by QDialog and then re-implement the "paintEvent" method with something similar to this:
Code:
// ... { Q_UNUSED(event) int titlebar_height = 0; // Titlebar. QStyleOptionTitleBar t_opt; t_opt.initFrom(this); t_opt.titleBarState = this->windowState(); t_opt.text = t_opt.fontMetrics.elidedText(this->windowTitle(), Qt::ElideRight, t_opt.rect.width()); style->drawItemText(&p, t_opt.rect, Qt::AlignCenter, t_opt.palette, true, t_opt.text, QPalette::ToolTipText); // Background widget. this->setContentsMargins(0, titlebar_height, 0, 0); QStyleOption w_opt; w_opt.initFrom(this); w_opt.rect = active_area; }
Now you can style it with a stylesheet:
Code:
MyDialog::title { height: 24px; font-weight: bold; color: #000000; background: #ffffff; }