Hello everybody,<br>
<br>
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.<br>
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). <br>
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.<br>
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.<br>
Thanks a lot.<br>
Here below my code.<br><br>import sys<br>from PyQt4.QtCore import * <br>from PyQt4.QtGui import *<br><br>class WizAndChipsCal(QWidget):<br><br> def __init__(self, parent = None):<br> QWidget.__init__(self)<br>
self.setWindowTitle("Wiz and Chips Calendar")<br> self.setWindowIcon(QIcon("C:/Python26/PyQt/Icon/date.png"))<br> self.setToolTip("Hello to this Wiz and Chips fancy calendar!")<br>
self.connect(self,<br> SIGNAL("QMouseEvent()"),<br> self.Opacity)<br> <br> self.title = ("<font color=red size=3><b>"\<br>
+ "Wiz and Chips Pushable Calendar!"\<br> + "</font></b>")<br> self.Label = QLabel(self.title)<br> self.Label.setAlignment(Qt.AlignCenter | Qt.AlignJustify)<br>
<br> self.calendar = QCalendarWidget()<br> self.calendar.setGridVisible(1)<br> self.calendar.setMinimumHeight(180)<br> self.calendar.setMinimumWidth(110)<br><br>
self.check1 = QCheckBox("check1")<br> self.check2 = QCheckBox("check2")<br> self.TextBox = QTextEdit("type something here")<br> self.TextBox.setMaximumHeight(50)<br>
<br> self.dateLabel = QLabel("Date:")<br> self.dateLabel.setMaximumWidth(80)<br> CurrDate = QDate.currentDate()<br> self.date = QDateEdit(CurrDate)<br>
self.date.setMaximumWidth(80)<br><br> self.CloseButton = QPushButton("&Quit")<br> self.CloseButton.setToolTip("<font color=red size=2><b>" + "Press here to Quit" + "</font></b>")<br>
self.CloseButton.setMaximumSize(50, 25)<br><br> self.infobox = QGroupBox("Info Box")<br> self.infobox.setCheckable(1)<br> self.infobox.setChecked(0)<br>
<br> dateLayout = QHBoxLayout()<br> dateLayout.addWidget(self.dateLabel)<br> dateLayout.addWidget(self.date)<br> dateLayout.addSpacing(170)<br> <br>
GBoxLayout = QVBoxLayout(self.infobox)<br> GBoxLayout.setSpacing(1)<br> GBoxLayout.addLayout(dateLayout)<br> GBoxLayout.addWidget(self.check1)<br> GBoxLayout.addWidget(self.check2)<br>
GBoxLayout.addWidget(self.TextBox)<br><br> Layout = QGridLayout()<br> Layout.addWidget(self.Label, 0, 0)<br> Layout.addWidget(self.calendar, 1, 0)<br> Layout.addWidget(self.CloseButton, 4, 0)<br>
Layout.addWidget(self.infobox, 3, 0)<br> self.setLayout(Layout)<br> self.connect(self.CloseButton, <br> SIGNAL("pressed()"), <br> self.close)<br>
<br> def Opacity(self):<br> while QMouseEvent(Qt.LeftButton):<br> self.setWindowOpacity(0.5)<br> else:<br> pass <br>
app = QApplication(sys.argv)<br>main_window = WizAndChipsCal()<br>main_window.show()<br>app.exec_()<br>