Use QStylePainter for drawing hover raised frames

This is needed for correct styling with Qt6 and is nicer code anyway
This commit is contained in:
Kovid Goyal 2022-01-16 05:14:55 +05:30
parent b29a8f8afa
commit 57d67d9deb
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 12 additions and 12 deletions

View File

@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
import functools import functools
from qt.core import ( from qt.core import (
QAction, QApplication, QDialog, QEvent, QIcon, QLabel, QMenu, QPainter, QAction, QApplication, QDialog, QEvent, QIcon, QLabel, QMenu, QStylePainter,
QSizePolicy, QSplitter, QStackedWidget, QStatusBar, QStyle, QStyleOption, Qt, QSizePolicy, QSplitter, QStackedWidget, QStatusBar, QStyle, QStyleOption, Qt,
QTabBar, QTimer, QToolButton, QVBoxLayout, QWidget QTabBar, QTimer, QToolButton, QVBoxLayout, QWidget
) )
@ -248,12 +248,12 @@ class VersionLabel(QLabel): # {{{
def paintEvent(self, ev): def paintEvent(self, ev):
if self.mouse_over: if self.mouse_over:
p = QPainter(self) p = QStylePainter(self)
tool = QStyleOption() tool = QStyleOption()
tool.initFrom(self)
tool.rect = self.rect() tool.rect = self.rect()
tool.state = QStyle.StateFlag.State_Raised | QStyle.StateFlag.State_Active | QStyle.StateFlag.State_MouseOver tool.state = QStyle.StateFlag.State_Raised | QStyle.StateFlag.State_Active | QStyle.StateFlag.State_MouseOver
s = self.style() p.drawPrimitive(QStyle.PrimitiveElement.PE_PanelButtonTool, tool)
s.drawPrimitive(QStyle.PrimitiveElement.PE_PanelButtonTool, tool, p, self)
p.end() p.end()
return QLabel.paintEvent(self, ev) return QLabel.paintEvent(self, ev)
# }}} # }}}

View File

@ -11,7 +11,7 @@ Job management.
import time import time
from qt.core import (QAbstractTableModel, QModelIndex, Qt, QPainter, from qt.core import (QAbstractTableModel, QModelIndex, Qt, QStylePainter,
QTimer, pyqtSignal, QIcon, QDialog, QAbstractItemDelegate, QApplication, QEvent, QTimer, pyqtSignal, QIcon, QDialog, QAbstractItemDelegate, QApplication, QEvent,
QSize, QStyleOptionProgressBar, QStyle, QToolTip, QWidget, QStyleOption, QSize, QStyleOptionProgressBar, QStyle, QToolTip, QWidget, QStyleOption,
QHBoxLayout, QVBoxLayout, QSizePolicy, QLabel, QCoreApplication, QAction, QItemSelectionModel, QHBoxLayout, QVBoxLayout, QSizePolicy, QLabel, QCoreApplication, QAction, QItemSelectionModel,
@ -602,12 +602,12 @@ class JobsButton(QWidget): # {{{
def paintEvent(self, ev): def paintEvent(self, ev):
if self.mouse_over: if self.mouse_over:
p = QPainter(self) p = QStylePainter(self)
tool = QStyleOption() tool = QStyleOption()
tool.initFrom(self)
tool.rect = self.rect() tool.rect = self.rect()
tool.state = QStyle.StateFlag.State_Raised | QStyle.StateFlag.State_Active | QStyle.StateFlag.State_MouseOver tool.state = QStyle.StateFlag.State_Raised | QStyle.StateFlag.State_Active | QStyle.StateFlag.State_MouseOver
s = self.style() p.drawPrimitive(QStyle.PrimitiveElement.PE_PanelButtonTool, tool)
s.drawPrimitive(QStyle.PrimitiveElement.PE_PanelButtonTool, tool, p, self)
p.end() p.end()
QWidget.paintEvent(self, ev) QWidget.paintEvent(self, ev)

View File

@ -3,7 +3,7 @@
from qt.core import ( from qt.core import (
QFontMetrics, QHBoxLayout, QIcon, QMenu, QPainter, QPushButton, QSize, QFontMetrics, QHBoxLayout, QIcon, QMenu, QStylePainter, QPushButton, QSize,
QSizePolicy, Qt, QWidget, QStyleOption, QStyle, QEvent) QSizePolicy, Qt, QWidget, QStyleOption, QStyle, QEvent)
@ -55,13 +55,13 @@ class LayoutItem(QWidget):
def paintEvent(self, ev): def paintEvent(self, ev):
shown = self.button.isChecked() shown = self.button.isChecked()
ls = self.fm.lineSpacing() ls = self.fm.lineSpacing()
painter = QPainter(self) painter = QStylePainter(self)
if self.mouse_over: if self.mouse_over:
tool = QStyleOption() tool = QStyleOption()
tool.initFrom(self)
tool.rect = self.rect() tool.rect = self.rect()
tool.state = QStyle.StateFlag.State_Raised | QStyle.StateFlag.State_Active | QStyle.StateFlag.State_MouseOver tool.state = QStyle.StateFlag.State_Raised | QStyle.StateFlag.State_Active | QStyle.StateFlag.State_MouseOver
s = self.style() painter.drawPrimitive(QStyle.PrimitiveElement.PE_PanelButtonTool, tool)
s.drawPrimitive(QStyle.PrimitiveElement.PE_PanelButtonTool, tool, painter, self)
painter.drawText( painter.drawText(
0, 0, 0, 0,
self.width(), self.width(),