Qt样式
来源:互联网 发布:绝地求生淘宝租号开挂 编辑:程序博客网 时间:2024/06/06 16:39
以下用一段qt助手中重绘QSpinBox控件风格代码为例
customstyle.cpp
#include "customstyle.h"#include <QStyleOption>#include <QPainter>CustomStyle::CustomStyle(){}void CustomStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const{ if (element == PE_IndicatorSpinUp || element == PE_IndicatorSpinDown) { QPolygon points(3); int x = option->rect.x(); int y = option->rect.y(); int w = option->rect.width() / 2; int h = option->rect.height() / 2; x += (option->rect.width() - w) / 2; y += (option->rect.height() - h) / 2; if (element == PE_IndicatorSpinUp) { points[0] = QPoint(x, y + h); points[1] = QPoint(x + w, y + h); points[2] = QPoint(x + w / 2, y); } else { // PE_SpinBoxDown points[0] = QPoint(x, y); points[1] = QPoint(x + w, y); points[2] = QPoint(x + w / 2, y + h); } if (option->state & State_Enabled) { painter->setPen(option->palette.mid().color()); painter->setBrush(option->palette.buttonText()); } else { painter->setPen(option->palette.buttonText().color()); painter->setBrush(option->palette.mid()); } painter->drawPolygon(points); } else { QProxyStyle::drawPrimitive(element, option, painter, widget); }}
main.cpp
#include <QApplication>#include "customstyle.h"#include <QSpinBox>int main(int argc, char *argv[]){ QApplication::setStyle(new CustomStyle); QApplication a(argc, argv); QSpinBox spinBox; spinBox.show(); return a.exec();}
阅读全文
0 0
- Qt样式
- Qt|Qt之鼠标样式
- QT 样式风格
- QT样式表
- QT样式表
- QT样式表
- QT样式表
- Qt QSS样式表
- Qt应用程序Cursor样式
- Qt应用程序Cursor样式
- Qt应用程序Cursor样式
- QT样式表
- Qt 样式表
- QT样式表
- Qt 样式表 setStyleSheet
- qt qlabel 样式
- Qt 光标样式
- qt样式表
- “GAN之父”Goodfellow与网友互动:关于GAN的11个问题(附视频)
- 用户空间和内核空间文件操作 file_operations
- Python编程之errorPython脚本运行出现语法错误
- 改变浏览器大小,ueditor宽度无法自适应
- 上拉输入与下拉输入
- Qt样式
- Java+Selenium3框架设计准备篇2-TestNG通过变量实现启动不同浏览器测试
- MYSQL中日期与字符串间的相互转换
- 用opencv计算棋盘格内角点坐标(通过4个内角点获得转换矩阵),并同时用halcon和opnecv对图像进行透视变换
- 通过ftp命令测试两台主机之间的网络情况
- python安装相关。
- 强大的Chrome浏览器的控制台!!!
- css行高line-height的一些深入理解及应用
- learning之适配器模式