已解决
Qt设置horizontal line 和vertical line的颜色
来自网友在路上 144844提问 提问时间:2023-10-22 01:47:04阅读次数: 44
最佳答案 问答题库448位专家为你答疑解惑
在Qt中,要设置水平线(QFrame)和垂直线(QSplitter)的颜色,可以使用样式表(stylesheet)或者直接设置QPalette。
下面是两种设置的示例:
- 使用样式表(stylesheet)设置颜色:
QFrame* horizontalLine = new QFrame(this);horizontalLine->move(20, 20);horizontalLine->setFixedHeight(1);horizontalLine->setFrameShape(QFrame::HLine);horizontalLine->setStyleSheet("background-color: red;"); // 设置水平线颜色为红色QSplitter* verticalLine = new QSplitter(Qt::Vertical, this);verticalLine->move(10,20);verticalLine->setFixedWidth(1);verticalLine->setLineWidth(1);verticalLine->setStyleSheet("background-color: blue;"); // 设置垂直线颜色为蓝色
使用样式表的优点在于可以更加灵活地设置样式,比如颜色、背景图像等。
- 使用QPalette设置颜色:
QFrame* horizontalLine = new QFrame();
horizontalLine->move(20, 20);
horizontalLine->setFixedHeight(1);
horizontalLine->setFrameShape(QFrame::HLine);
QPalette pal = palette();
pal.setColor(QPalette::Background, Qt::red);
horizontalLine->setAutoFillBackground(true);
horizontalLine->setPalette(pal); // 设置水平线颜色为红色QSplitter* verticalLine = QSplitter(Qt::Vertical);
verticalLine->move(10,20);
verticalLine->setFixedWidth(1);
verticalLine->setLineWidth(1);
QPalette pal = palette();
pal.setColor(QPalette::Background, Qt::blue);
verticalLine->setAutoFillBackground(true);
verticalLine->setPalette(pal); // 设置垂直线颜色为蓝色
效果:
使用QPalette设置颜色时,需要设置QFrame和QSplitter的背景色(QPalette::Background)为所需的颜色。
通过设置setAutoFillBackground(true)来启用自动填充背景色。
这两种方法都可以用来设置水平线和垂直线的颜色,可以选择适合自己的方法来设置。
查看全文
99%的人还看了
相似问题
- QT中样式表常见属性与颜色的设置与应用
- OpenLayers实战,WebGL图层根据Feature要素的变量动态渲染多种颜色的三角形,适用于大量三角形渲染不同颜色
- Threejs_08 纹理颜色的调整(颜色空间的设置)
- 数据处理生产环境_利用MurmurHash3算法在Spark和Scala中生成随机颜色
- vue中使用echarts实现省市地图绘制,根据数据显示不同区域颜色,点击省市切换,根据经纬度打点
- 【CSS】各百分比透明度 opacity 对应的 16 进制颜色值(例如:#FFFFFF80)
- BetterDisplay Pro v2.0.11(显示器颜色校准软件)
- Kotlin语言实现单击任意TextVIew切换一个新页面,并且实现颜色变换
- vColorPicker与vue3-colorPicker——基于 Vue 的颜色选择器插件
- PySide/PYQT如何用Qt Designer和代码来设置文字属性,如何设置文字颜色?
猜你感兴趣
版权申明
本文"Qt设置horizontal line 和vertical line的颜色":http://eshow365.cn/6-21220-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!
- 上一篇: 【vue】在vue.config.js文件中导入模块
- 下一篇: 网络基础知识点