qt样式表

zl_lg_2009 2015-10-28 04:52:50
自定义控件重写paintEvent,怎么获取样式表中的属性用于绘制
...全文
142 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
hidxl 2015-10-29
  • 打赏
  • 举报
回复
看QT帮助,如 : Developing Style-Aware Custom Widgets If you are developing custom widgets and want them to look good on all platforms, you can use QStyle functions to perform parts of the widget drawing, such as drawItemText(), drawItemPixmap(), drawPrimitive(), drawControl(), and drawComplexControl(). Most QStyle draw functions take four arguments: an enum value specifying which graphical element to draw a QStyleOption specifying how and where to render that element a QPainter that should be used to draw the element a QWidget on which the drawing is performed (optional) For example, if you want to draw a focus rectangle on your widget, you can write: void MyWidget::paintEvent(QPaintEvent * /* event */) { QPainter painter(this); QStyleOptionFocusRect option; option.initFrom(this); option.backgroundColor = palette().color(QPalette::Background); style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this); }

16,212

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧