stylesheet无效
来源:互联网 发布:手机号抓取软件 编辑:程序博客网 时间:2024/05/11 18:15
//sheetstyle file, style.cssQWidget#setting_widget{ background-color: white;}//child widgetclass CSubWidget : public QWidget{ Q_OBJECTpublic: explicit CSettingWidget(QWidget *parent = 0);};CSettingWidget::CSettingWidget(QWidget *parent) : QWidget(parent){ setWindowFlags(Qt::WindowStaysOnTopHint); setObjectName("subwidget");}//main widgetclass MainWindow : public QWidget{ Q_OBJECTpublic: ~MainWindow(); explicit MainWindow(QWidget *parent = 0);private: CSubWidget *m_pSubWidget;};MainWindow::MainWindow(QWidget *parent) : QWidget(parent){ QFile file(":/style.css"); file.open(QIODevice::ReadOnly); qApp->setStyleSheet(file.readAll()); m_pSubWidget = new CSubWidget(this);}
以上会发现, CSubWidget 设置的窗体样式是无效的,
查看文档会发现
QWidgetSupports only the background, background-clip and background-origin properties.If you subclass from QWidget, you need to provide a paintEvent for your custom QWidget as below:
void CustomWidget::paintEvent(QPaintEvent *){ QStyleOption opt; opt.init(this); QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);}
The above code is a no-operation if there is no stylesheet set.Warning: Make sure you define the Q_OBJECT macro for your custom widget.
为CSubWidget 加上paintEvent就可以解决
0 0
- stylesheet无效
- styleSheet样式无效
- StyleSheet
- StyleSheet 接口
- qt stylesheet
- QProgressBar stylesheet
- Qt stylesheet
- qt stylesheet
- QTabWidget StyleSheet
- RN stylesheet
- Qt Stylesheet
- as3.0 StyleSheet htmltext使用stylesheet
- styleSheet的动态修改
- test stylesheet.css
- CSS-Cascading StyleSheet
- qt4 StyleSheet的总结
- 利用stylesheet设置Q_PROPERTY
- XSTL Extensible Stylesheet Transformation
- scrollView嵌套的listview里又嵌套了GridView,实现下拉刷新和加载更多(附源码)亲测可用
- yii2.0域名目录绑定(二级域名)以及url美化 url伪静态 Apache 和 IIS
- 51 nod 1050
- Python学习笔记-Dictionary 【python 3】//为继续学习爬虫准备-00
- java使用RSA算法加密解密
- stylesheet无效
- 学习安卓的感悟?
- 静态成员
- springMVC form表单提交---包含时间类型的数据
- JAVA HTTP GET/POST
- 看看JAVA中类的实例化步骤
- 179. Largest Number
- 如何自学ANDROID编程
- ListView条目点击侦听和Adapter的getView调用