source: orange/Orange/OrangeCanvas/gui/framelesswindow.py @ 11104:cbc940675838

Revision 11104:cbc940675838, 1.5 KB checked in by Ales Erjavec <ales.erjavec@…>, 19 months ago (diff)

Added FramelessWindow class.

Line 
1"""
2A Frameless window widget
3
4"""
5
6from PyQt4.QtGui import QWidget, QPalette, QPainter, QStyleOption
7
8from PyQt4.QtCore import Qt, pyqtProperty as Property
9
10from .utils import is_transparency_supported, StyledWidget_paintEvent
11
12
13class FramelessWindow(QWidget):
14    """A Basic frameless window widget with rounded corners (if supported by
15    the windowing system).
16
17    """
18    def __init__(self, parent=None, **kwargs):
19        QWidget.__init__(self, parent, **kwargs)
20        self.setWindowFlags(Qt.FramelessWindowHint)
21
22        self.__radius = 6
23        self.__isTransparencySupported = is_transparency_supported()
24        self.setAttribute(Qt.WA_TranslucentBackground,
25                          self.__isTransparencySupported)
26
27    def setRadius(self, radius):
28        """Set the window rounded border radius.
29        """
30        if self.__radius != radius:
31            self.__radius = radius
32            self.update()
33
34    def radius(self):
35        return self.__radius
36
37    radius_ = Property(int, fget=radius, fset=setRadius)
38
39    def paintEvent(self, event):
40        if self.__isTransparencySupported:
41            p = QPainter(self)
42            p.setRenderHint(QPainter.Antialiasing, True)
43
44            opt = QStyleOption()
45            opt.init(self)
46            rect = opt.rect
47            p.setBrush(opt.palette.brush(QPalette.Window))
48            p.setPen(Qt.NoPen)
49            p.drawRoundedRect(rect, self.__radius, self.__radius)
50            p.end()
51        else:
52            StyledWidget_paintEvent(self, event)
Note: See TracBrowser for help on using the repository browser.