gpt4 book ai didi

python - 仅来自 Qt5 ColorDialog 的颜色渐变

转载 作者:行者123 更新时间:2023-12-01 15:34:25 24 4
gpt4 key购买 nike

我想问一下是否可以只使用 QColorDialog 的颜色渐变(红色包围)部分。

QColorDialog

我在不同的 Linux 机器(ubuntu + raspian)上使用 PyQt5 和 Python3。

最佳答案

只需要隐藏除QColorPickerQColorLuminancePicker之外的所有元素即可。

import sys

from PyQt5 import QtCore, QtGui, QtWidgets


class ColorDialog(QtWidgets.QColorDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setOptions(self.options() | QtWidgets.QColorDialog.DontUseNativeDialog)

for children in self.findChildren(QtWidgets.QWidget):
classname = children.metaObject().className()
if classname not in ("QColorPicker", "QColorLuminancePicker"):
children.hide()


if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)

colordialog = ColorDialog()
label = QtWidgets.QLabel(alignment=QtCore.Qt.AlignCenter)

def onCurrentColorChanged(color):
label.setStyleSheet("background-color: {}".format(color.name()))

colordialog.currentColorChanged.connect(onCurrentColorChanged)
onCurrentColorChanged(colordialog.currentColor())

w = QtWidgets.QWidget()
lay = QtWidgets.QVBoxLayout(w)
lay.addWidget(colordialog, alignment=QtCore.Qt.AlignCenter)
lay.addWidget(label)
w.show()

sys.exit(app.exec_())

enter image description here

关于python - 仅来自 Qt5 ColorDialog 的颜色渐变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59848923/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com