【发布时间】:2020-03-23 13:38:00
【问题描述】:
我正在开发颜色选择器,并创建了一个混合颜色的面板。 面板的第一部分可以创建颜色的色调、色调和阴影,第二部分可以使用 2 种颜色进行混合。
但是我遇到了一个奇怪的情况,我在小部件上的渐变表示不反映它正在计算的实际颜色。 在这里你可以看到我使用“GREEN”和“PINK”并且渐变是相同的(RGB渐变?) 我通过使用 RGB 颜色空间计算顶栏的插值以及在 HSV 中插值的第二栏来实现这一点,这就是他们实际给出的结果。
这是我在托管我的代码的绘画程序上的渐变测试(上)与实际颜色混合器(下)的比较,它确实在 HSV 中显示。
如何在我的小部件上实现这种渐变过渡表示?
代码测试:
def paintEvent(self, event):
green = QColor('#3c552c')
pink = QColor('#d9bdcf')
painter = QPainter(self)
painter.setPen(QPen(Qt.black, 4, Qt.SolidLine))
grad1 = QLinearGradient(20,20,190,20)
grad1.setColorAt(0.0, green)
grad1.setColorAt(1.0, pink)
painter.setBrush(QBrush(grad1))
painter.drawRect(10,10,200,200)
当前使用的代码:
def Mixer_Display(self):
# Display Color with Tint, Tone, Shade
mix_color_tint = str("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgb(%f, %f, %f), stop:1 rgb(255, 255, 255));" % (self.color_n_red, self.color_n_green, self.color_n_blue))
self.layout.color_tint.setStyleSheet(mix_color_tint)
mix_color_tone = str("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgb(%f, %f, %f), stop:1 rgb(127, 127, 127));" % (self.color_n_red, self.color_n_green, self.color_n_blue))
self.layout.color_tone.setStyleSheet(mix_color_tone)
mix_color_shade = str("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgb(%f, %f, %f), stop:1 rgb(0, 0, 0));" % (self.color_n_red, self.color_n_green, self.color_n_blue))
self.layout.color_shade.setStyleSheet(mix_color_shade)
# Display Gradients
mix_gradient_1 = str("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgb(%f, %f, %f), stop:1 rgb(%f, %f, %f));" % (self.color_l1_red, self.color_l1_green, self.color_l1_blue, self.color_r1_red, self.color_r1_green, self.color_r1_blue))
self.layout.gradient_1.setStyleSheet(mix_gradient_1)
mix_gradient_2 = str("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgb(%f, %f, %f), stop:1 rgb(%f, %f, %f));" % (self.color_l2_red, self.color_l2_green, self.color_l2_blue, self.color_r2_red, self.color_r2_green, self.color_r2_blue))
self.layout.gradient_2.setStyleSheet(mix_gradient_2)
mix_gradient_3 = str("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgb(%f, %f, %f), stop:1 rgb(%f, %f, %f));" % (self.color_l3_red, self.color_l3_green, self.color_l3_blue, self.color_r3_red, self.color_r3_green, self.color_r3_blue))
self.layout.gradient_3.setStyleSheet(mix_gradient_3)
【问题讨论】:
-
你把“实际颜色混合器”带到哪里去了?
-
它是别人的插件,我只是在上面挑了相同的颜色来显示颜色差异。
-
所以这个人所做的可能是使用另一种颜色插值,可能基于 HSV 颜色空间。如果您知道该插件的来源,您可以在其代码中了解它是如何完成的。
-
我不知道渐变是从哪里来的:\
-
插件名称是什么?
标签: python-3.x pyqt5