diff --git a/qutebrowser/utils/style.py b/qutebrowser/utils/style.py index 92d5006a9..10bdd2f45 100644 --- a/qutebrowser/utils/style.py +++ b/qutebrowser/utils/style.py @@ -27,16 +27,11 @@ import functools from PyQt5.QtWidgets import QCommonStyle, QStyle -class Style(QCommonStyle): +class ProxyStyle(QCommonStyle): - """Qt style to remove Ubuntu focus rectangle uglyness. - - Unfortunately PyQt doesn't support QProxyStyle, so we need to do this the - hard way... + """Helper to create a Qt proxy style as PyQt doesn't support QProxyStyle. Based on: - - http://stackoverflow.com/a/17294081 https://code.google.com/p/makehuman/source/browse/trunk/makehuman/lib/qtgui.py Attributes: @@ -57,11 +52,20 @@ class Style(QCommonStyle): 'hitTestComplexControl', 'itemPixmapRect', 'itemTextRect', 'pixelMetric', 'polish', 'styleHint', 'subControlRect', 'subElementRect', 'unpolish', - 'sizeFromContents'): - target = getattr(self._style, method) - setattr(self, method, functools.partial(target)) + 'sizeFromContents', 'drawPrimitive'): + if not getattr(self, method): + target = getattr(self._style, method) + setattr(self, method, functools.partial(target)) super().__init__() + +class NoFocusRectStyle(ProxyStyle): + + """Qt style to remove Ubuntu focus rectangle uglyness. + + Based on http://stackoverflow.com/a/17294081 + """ + def drawPrimitive(self, element, option, painter, widget=None): """Override QCommonStyle.drawPrimitive. diff --git a/qutebrowser/widgets/tabwidget.py b/qutebrowser/widgets/tabwidget.py index 3c9c116ea..b51d32141 100644 --- a/qutebrowser/widgets/tabwidget.py +++ b/qutebrowser/widgets/tabwidget.py @@ -25,7 +25,7 @@ from PyQt5.QtGui import QIcon, QPixmap import qutebrowser.config.config as config from qutebrowser.config.style import set_register_stylesheet -from qutebrowser.utils.style import Style +from qutebrowser.utils.style import NoFocusRectStyle class EmptyTabIcon(QIcon): @@ -80,9 +80,9 @@ class TabWidget(QTabWidget): def __init__(self, parent): super().__init__(parent) + self.setStyle(NoFocusRectStyle(self.style())) self.setTabBar(TabBar()) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) - self.setStyle(Style(self.style())) set_register_stylesheet(self) self.setDocumentMode(True) self.setElideMode(Qt.ElideRight)