created a window with a lineedit, pushbutton and a label. whenever pushbutton is pressed, some action should be happened and while processing the action event the label should show the text in it and hide the text after processing the button mouse press event action.
But in my case, the text is visible when the press event is in process. Below i have attached the sample source pyqt code.
I hope someone might have the clue to achieve it.
Thanks
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
import sys
import PyQt4.QtGui as QtGui
import PyQt4.QtCore as QtCore
import time
labelText = None
class Dialog(QtGui.QDialog):
def __init__(self, parent=None):
super().__init__(parent)
main = QtGui.QVBoxLayout()
self.lineEdit = QtGui.QLineEdit()
main.addWidget(self.lineEdit)
self.pushButton = QtGui.QPushButton()
self.pushButton.setText(QtGui.QApplication.translate("Form", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setObjectName("self.pushButton")
self.pushButton.setFocusPolicy(QtCore.Qt.NoFocus)
main.addWidget(self.pushButton)
self.label = QtGui.QLabel()
self.label.setText('AM I Visible To U?')
main.addWidget(self.label)
global labelText
labelText = self.label
self.label.hide()
self.setLayout(main)
self.setMinimumSize(150, 150)
QtCore.QObject.connect(self.lineEdit, QtCore.SIGNAL('returnPressed()'), self.pushed)
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL('clicked()'), self.pushed)
def pushed(self):
print('..........start to sleep...............')
global labelText
labelText.hide()
time.sleep(2)
print('stopped sleeping....')
class PushButton(QtGui.QPushButton):
def __init__(self):
super().__init__()
def mousePressEvent(self, keyEvent):
global labelText
labelText.show()
super().keyPressEvent(keyEvent)
class LineEdit(QtGui.QLineEdit):
def __init__(self):
super().__init__()
def keyPressEvent(self, keyEvent):
global labelText
if keyEvent.key() in [QtCore.Qt.Key_Return]:
labelText.show()
super().keyPressEvent(keyEvent)
if __name__ == "__main__":
app = QtGui.QApplication([])
dialog = Dialog()
sys.exit(dialog.exec_())
|