Swatches pyqt5 taken by drawing QLinearGradient

To draw take HSV swatches, typically by way of drawing foreground and background colors of realization, the first drawing foreground, and then drawing the background, the foreground is an HSV color space, from left to right, the brightness of the background, from top to bottom, and ys XS It is the current location of the mouse.

    def graphicsView_rgb_palette(self,xs,ys):
        try:
            rect = QRectF(0, 0, self.graphicsView_color_palette.width() - 2,
                          self.graphicsView_color_palette.height() - 2)
            self.graphicsView_color_palette_scene = QGraphicsScene(rect)  # 创建场景
            self.graphicsView_color_palette.setScene(self.graphicsView_color_palette_scene)
            #前景,HSV空间 ,从360到0
            colorGradient = QLinearGradient(0, 0, self.graphicsView_color_palette.width(),0)
            colorGradient.setSpread(QGradient.RepeatSpread);
            colorGradient.setColorAt(0, QColor(255, 0, 0, 255));
            colorGradient.setColorAt(0.166, QColor(255, 255, 0, 255));
            colorGradient.setColorAt(0.333, QColor(0, 255, 0, 255));
            colorGradient.setColorAt(0.5, QColor(0, 255, 255 , 255 )); 
            colorGradient.setColorAt ( 0.666 , a QColor ( 0 , 0 , 255 , 255 )); 
            colorGradient.setColorAt ( 0.833 , a QColor ( 255 , 0 , 255 , 255 )); 
            colorGradient.setColorAt ( . 1 , a QColor ( 255 , 0 , 0 , 255 )); 

            # bACKGROUND, adjust brightness, transparency uppermost, lowermost white 
            blackGradient = qlineargradient ( 0 ,0 , 0 , self.graphicsView_color_palette.height ()) 
            blackGradient.setSpread (QGradient.RepeatSpread); 
            blackGradient.setColorAt ( 0 , a QColor ( 0 , 0 , 0 , 0 )); 
            blackGradient.setColorAt ( . 1 , a QColor ( 255 , 255 , 255 , 250 )); 
            # Swatches mouse pointer points plotted take 
            Item = QGraphicsEllipseItem (- 10 , - 10 , 20 is , 20 is ) # Create oval - scene coordinate
            item.setPos (xs, ys) # primitive provided to the coordinates in the scene (moving elements) - primitive center coordinates 
            item.setBrush (Qt.black) # brush provided 
            # 
            self.graphicsView_color_palette_scene.setBackgroundBrush (colorGradient) ; set # foreground 
            self.graphicsView_color_palette_scene.setForegroundBrush (blackGradient); # background color 

            self.graphicsView_color_palette_scene.addItem (Item) 
            self.graphicsView_color_palette_scene.clearSelection () # [selection] Clear 
        the except Exception AS E: 
            self.UART_Display_Text (STR (E ))

Guess you like

Origin www.cnblogs.com/zhouzhengbao-bky/p/12196673.html
Recommended