How to get widget background QColor

牧云@^-^@ 提交于 2019-12-30 17:24:13

问题


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).

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.


回答1:


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.



来源:https://stackoverflow.com/questions/15519749/how-to-get-widget-background-qcolor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!