Qt 控件透明化:使用样式表和属性设置
"Qt 让空间变透明的样式表语句"如果你想让 Qt 控件变透明,可以使用样式表语句 background-color: transparent;
,它将控件的背景颜色设置为透明。以下是一个示例:\n\ncpp\n// 创建一个 QWidget 控件\nQWidget *widget = new QWidget();\n\n// 设置样式表\nwidget->setStyleSheet("background-color: transparent;");\n
\n\n这将使得 widget
控件的背景透明。请注意,如果你想让控件的内容也透明,你还需要设置 setAttribute(Qt::WA_TranslucentBackground)
。\n\ncpp\n// 设置控件内容透明\nwidget->setAttribute(Qt::WA_TranslucentBackground);\n
原文地址: http://www.cveoy.top/t/topic/pNqe 著作权归作者所有。请勿转载和采集!