diff --git a/enaml/qt/q_popup_view.py b/enaml/qt/q_popup_view.py index 2aa28d6be..a7e42e087 100644 --- a/enaml/qt/q_popup_view.py +++ b/enaml/qt/q_popup_view.py @@ -10,7 +10,7 @@ pyqtSignal ) from PyQt4.QtGui import ( - QApplication, QFrame, QLayout, QPainter, QPainterPath, QRegion, QPen + QApplication, QWidget, QLayout, QPainter, QPainterPath, QRegion, QPen ) from atom.api import Atom, Typed, Float, Int @@ -18,8 +18,8 @@ from .q_single_widget_layout import QSingleWidgetLayout -class QPopupView(QFrame): - """ A custom QFrame which implements a framless popup widget. +class QPopupView(QWidget): + """ A custom QWidget which implements a framless popup widget. It is useful for showing transient configuration dialogs as well as temporary notification windows. @@ -115,7 +115,6 @@ def __init__(self, parent=None, flags=Qt.Popup): """ super(QPopupView, self).__init__(parent) self.setWindowFlags(flags | Qt.FramelessWindowHint) - self.setAttribute(Qt.WA_TranslucentBackground) self.setAttribute(Qt.WA_DeleteOnClose) layout = QSingleWidgetLayout() layout.setSizeConstraint(QLayout.SetMinAndMaxSize) @@ -473,7 +472,6 @@ def paintEvent(self, event): """ Handle the paint event for the popup view. """ - super(QPopupView, self).paintEvent(event) palette = self.palette() fill_color = palette.window().color() stroke_color = palette.windowText().color() diff --git a/enaml/qt/qt_popup_view.py b/enaml/qt/qt_popup_view.py index bcde4fa2e..1c50306f1 100644 --- a/enaml/qt/qt_popup_view.py +++ b/enaml/qt/qt_popup_view.py @@ -43,8 +43,11 @@ def create_widget(self): """ Create the QPopupView widget. """ - flags = WINDOW_TYPES[self.declaration.window_type] + d = self.declaration + flags = WINDOW_TYPES[d.window_type] self.widget = QPopupView(self.parent_widget(), flags) + if d.translucent_background: + self.widget.setAttribute(Qt.WA_TranslucentBackground) def init_widget(self): """ Initialize the widget. diff --git a/enaml/widgets/popup_view.py b/enaml/widgets/popup_view.py index 15a4b2091..9b4993889 100644 --- a/enaml/widgets/popup_view.py +++ b/enaml/widgets/popup_view.py @@ -6,7 +6,8 @@ # The full license is in the file COPYING.txt, distributed with this software. #------------------------------------------------------------------------------ from atom.api import ( - Coerced, Enum, Float, Event, Int, Typed, ForwardTyped, observe, set_default + Bool, Coerced, Enum, Float, Event, Int, Typed, ForwardTyped, observe, + set_default ) from enaml.application import deferred_call @@ -142,6 +143,13 @@ class PopupView(Widget): #: or equal to zero means no fade. fade_out_duration = d_(Int(100)) + #: Whether or not the background of the popup view is translucent. + #: This must be True in order to use background colors with alpha + #: and for the fade in and out animation to have effect. This value + #: must be set before the popup view is shown. Changes to this value + #: after the popup is shown will have no effect. + translucent_background = d_(Bool(True)) + #: An event emitted when the view is closed. After this event is #: fired, the view will be destroyed and should not be used. closed = d_(Event(), writable=False)