C++ 更改QWidget标题颜色
我有一个名为Window的自定义类,它扩展了QWidgetC++ 更改QWidget标题颜色,c++,qt,qwidget,C++,Qt,Qwidget,我有一个名为Window的自定义类,它扩展了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 *) {
#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:
执行此操作时,按钮(最小化、最大化和关闭)消失(如下图所示)
所以我的问题是,如何正确设置窗口标题栏的样式?通过
this->setStyleSheet()在构造函数中设置样式
忘记css?也许你可以在默认的QWindow上使用this->styleSheet()
,看看你缺少了什么?@user3528438这不起作用,如果我这样做了:QWidget{background color:black}它会起作用,但是如果我做了QWidget:title,什么也没发生。不要认为用Qt以平台无关的方式设计窗口标题栏是可能的。它并没有得到真正的支持,结果可能会有所不同。据我所知,具有样式标题栏的应用程序往往是无框架窗口,使用自定义代码处理通常由窗口框架处理的所有绘图和输入。^--是真的。这里有一个例子。
QWidget:title
{
background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #ffa02f, stop: 1 #ca0619);
}