How to create graphic slider in Python that can be modified with mouse?(如何在Python中创建可以用鼠标修改的图形滑块?)
本文介绍了如何在Python中创建可以用鼠标修改的图形滑块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在PyQt中创建可用鼠标从0修改为100的类似于进度条的图形滑块?
QSlider
您必须适当设置推荐答案样式表。此解决方案基于PyQt5
import sys
from PyQt5 import QtGui, QtCore, QtWidgets
class MyApp(object):
def __init__(self):
super(MyApp, self).__init__()
self.mainWidget = QtWidgets.QWidget()
self.mainLayout = QtWidgets.QVBoxLayout()
self.mainWidget.setLayout(self.mainLayout)
self.slider = QtWidgets.QSlider()
self.slider.setOrientation(QtCore.Qt.Horizontal)
self.slider.setStyleSheet(self.stylesheet())
self.mainLayout.addWidget(self.slider)
self.mainWidget.show()
sys.exit(app.exec_())
def stylesheet(self):
return """
QSlider::groove:horizontal {
background: white;
height: 40px;
}
QSlider::sub-page:horizontal {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #66e, stop: 1 #bbf);
background: qlineargradient(x1: 0, y1: 0.2, x2: 1, y2: 1,
stop: 0 #bbf, stop: 1 #55f);
height: 40px;
}
QSlider::add-page:horizontal {
background: #fff;
height: 40px;
}
QSlider::handle:horizontal {
background: #bbf;
border: 0px;
width: 0px;
margin-top: 0px;
margin-bottom: 0px;
border-radius: 0px;
}
"""
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
MyApp()
这是输出组件
这篇关于如何在Python中创建可以用鼠标修改的图形滑块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:如何在Python中创建可以用鼠标修改的图形滑块?
基础教程推荐
猜你喜欢
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 包装空间模型 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 求两个直方图的卷积 2022-01-01
