PDA

View Full Version : Change QWidget Title Color



binarysolo
17th April 2015, 03:05
I have a custom class called Window that extends QWidget.


#include "window.h"

// This is the base that all (MDI) sub-windows extend off

Window::Window()
{
// Add fake icon to remove icon in all
setWindowIcon(QIcon("."));
}

void Window::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

css:


QWidget:title
{
background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #ffa02f, stop: 1 #ca0619);
}

When I do this the buttons (minimize, maximize and close) disappear (as seen in the picture below).

11097

So my question, how do I properly style my Window titlebar?

Lykurg
17th April 2015, 05:41
Well, unfortunately, it is not as easy as you think. For an introduction have a look at http://www.qt-coding.com/2013/08/01/customize-window-title-styles-and-buttons/