Clean up styles

This commit is contained in:
Florian Bruhin 2014-06-19 15:43:34 +02:00
parent 4235034604
commit f821d9e211
2 changed files with 16 additions and 12 deletions

View File

@ -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.

View File

@ -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)