如何获取小部件背景 QColor [英] How to get widget background QColor

查看:77
本文介绍了如何获取小部件背景 QColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出 QWidgetQGLWidget 的背景颜色,以便我可以将它与 qglClearColor() 一起使用来制作OpenGL 部分本机出现在小部件中(例如没有黑色背景).

I am trying to find out the background color of a QWidget or QGLWidget so that I can use it with qglClearColor() to make the OpenGL part appear natively within the widget (without for example a black background).

我想我可以获取我的小部件的 backgroundRole(),但是我在将它转换为 QColor 时遇到了问题.有 QPalette::color(QColorRole) 但它不是静态的,我不知道如何创建 QPalette 的实例来进行转换.

I figured I could fetch backgroundRole() of my widget but I am having problems converting it to a QColor. There is QPalette::color(QColorRole) but it isn't static and I have no idea how I would have to create an instance of QPalette to do the transformation.

推荐答案

使用QWidget::palette().color(QWidget::backgroundRole())接收背景色角色的颜色对于那个小部件.显然,这也适用于任何继承 QWidget 的类.

Use QWidget::palette().color(QWidget::backgroundRole())to receive the color of the background color role for that widget. Obviously, this should also work with any class that inherits QWidget.

这篇关于如何获取小部件背景 QColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆