[PyQt] problem with main window opacity (signal&slot)

Gabriele Visconti gabriele.visconti at gmail.com
Tue Feb 17 14:47:45 GMT 2009


Hello everybody,

I'm experimenting with PyQt, trying to learn it, and I'm a bit stuck with
Signals and Slots. I don't usually like just to repeat the examples you find
in tutorials and guides because I think it's more useful for learning to
experiment concepts by yourself. Tutorials usually teach you doing the most
basic things which, once learnt, nearly never apply to your personal
situation or usage.
What I want to do is to replicate the KDE effect, you know that when you
grab a window and drag it around the window temporary becomes transparent
(low alpha).
I found the relevant Qt class which is setWindowOpacity(), I tried to build
a signal-slot system which when the left mouse is pressed on the main widget
(i.e. for dragging it around) the widget will become transparent.
I can't obtain this effect. There's no traceback error it simply does
nothing. Of course I missed something important. Any suggestion or help to
solve my problem.
Thanks a lot.
Here below my code.

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class WizAndChipsCal(QWidget):

        def __init__(self, parent = None):
                QWidget.__init__(self)
                self.setWindowTitle("Wiz and Chips Calendar")
                self.setWindowIcon(QIcon("C:/Python26/PyQt/Icon/date.png"))
                self.setToolTip("Hello to this Wiz and Chips fancy
calendar!")
                self.connect(self,
                             SIGNAL("QMouseEvent()"),
                             self.Opacity)

                self.title = ("<font color=red size=3><b>"\
                              + "Wiz and Chips Pushable Calendar!"\
                              + "</font></b>")
                self.Label = QLabel(self.title)
                self.Label.setAlignment(Qt.AlignCenter | Qt.AlignJustify)

                self.calendar = QCalendarWidget()
                self.calendar.setGridVisible(1)
                self.calendar.setMinimumHeight(180)
                self.calendar.setMinimumWidth(110)

                self.check1 = QCheckBox("check1")
                self.check2 = QCheckBox("check2")
                self.TextBox = QTextEdit("type something here")
                self.TextBox.setMaximumHeight(50)

                self.dateLabel = QLabel("Date:")
                self.dateLabel.setMaximumWidth(80)
                CurrDate = QDate.currentDate()
                self.date = QDateEdit(CurrDate)
                self.date.setMaximumWidth(80)

                self.CloseButton = QPushButton("&Quit")
                self.CloseButton.setToolTip("<font color=red size=2><b>" +
"Press here to Quit" + "</font></b>")
                self.CloseButton.setMaximumSize(50, 25)

                self.infobox = QGroupBox("Info Box")
                self.infobox.setCheckable(1)
                self.infobox.setChecked(0)

                dateLayout = QHBoxLayout()
                dateLayout.addWidget(self.dateLabel)
                dateLayout.addWidget(self.date)
                dateLayout.addSpacing(170)

                GBoxLayout = QVBoxLayout(self.infobox)
                GBoxLayout.setSpacing(1)
                GBoxLayout.addLayout(dateLayout)
                GBoxLayout.addWidget(self.check1)
                GBoxLayout.addWidget(self.check2)
                GBoxLayout.addWidget(self.TextBox)

                Layout = QGridLayout()
                Layout.addWidget(self.Label, 0, 0)
                Layout.addWidget(self.calendar, 1, 0)
                Layout.addWidget(self.CloseButton, 4, 0)
                Layout.addWidget(self.infobox, 3, 0)
                self.setLayout(Layout)
                self.connect(self.CloseButton,
                             SIGNAL("pressed()"),
                             self.close)

        def Opacity(self):
                while QMouseEvent(Qt.LeftButton):
                        self.setWindowOpacity(0.5)
                else:
                        pass
app = QApplication(sys.argv)
main_window = WizAndChipsCal()
main_window.show()
app.exec_()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090217/b115b007/attachment.html


More information about the PyQt mailing list