[Python] What's the correct way to customize the look of a custom painted Qt Widget?

Discussão em 'Python' iniciado por Stack, Julho 21, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on an advanced UI made with Qt (PySide2 in Python) and an important part of my widgets are custom implementation (subclass) of QWidget with important drawing made in the paintEvent. (Some context: A MiniMap Widget that draws a QtextDocument as well as some indications (diff, cursor, breakpoint, whatever). Or simpler, a QPlainTextEdit subclass that draw a ruler, current line background, matching brackets, etc...)

    What I'm not sure about right now is how to properly customize the look of my widgets as the QPalette doesn't seems to give enough options for my needs. (I can't seem to easily allow a different color for the background, the current line background, the rulet color, indent guides, matching brackets). I could use some less used Roles, like "Link", but it quickly becomes hard to follow and maintain. The other option would be to use Style Sheets, but in my experience it has quite some flows and doesn't pair well with QPalettes and QStyle.

    My end goal is to be able to load colors from a config file (the color scheme of the editor I'm building).

    Is there any good practice I could refer too, or could anybody give me some advices or recommendations please ?

    Continue reading...

Compartilhe esta Página