How do you read the current colors QPalette() of element QApplication in pyqt5?



  • #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    from PyQt5.QtWidgets import *
    from PyQt5.QtGui import QKeySequence, QPalette, QColor
    from PyQt5.QtCore import Qt
    
    app = QApplication([])
    
    palette = QPalette()
    palette.setColor(QPalette.Window, QColor(53, 53, 53))
    

    How do I read Window's color that is now in place?



  • In fact, just like you in your example, you're setting it up.

    color = palette.color(QPalette.Window) 
    

    More detailed here. https://doc.qt.io/qt-5/qpalette.html#color-1

    Colours in Qt are presented by QColor, a copy of which is returned. If you need to get RGB or other parameters, work with QColor.

    color = palette.color(QPalette.Window)
    name = color.name()
    rgb = f'RED={color.red()} GREEN={color.green()} BLUE={color.blue()}'
    print(f'by name: {name}\n as RGB: {rgb}\n')
    

    https://doc.qt.io/qt-5/qcolor.html


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2