You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Tuesday, February 28th 2012, 11:47am

mouse press event for the pushbutton is not processing properly

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_())

This post has been edited 1 times, last edit by "mathan" (Feb 28th 2012, 1:18pm)


2

Tuesday, February 28th 2012, 12:14pm

I'm confused - you want to hide the label after processing. where is your code for hiding the label?
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

3

Tuesday, February 28th 2012, 1:23pm

sorry, Edited above @ line no 37 to hide the label.

My Aim:
initially label is hidden and when the button is pressed, at once i want to show the label only when the button press event is in process. Also label should be hided after processing the button press event/action.

What i get :
label is not shown while the button press event is in process. i dont know why?

4

Tuesday, February 28th 2012, 2:20pm

err, so hide it AFTER the sleep.

Source code

1
2
3
4
5
6
7
8
def pushed(self):
        labelText.show()
    	print('..........start to sleep...............')
    	global labelText
    	
    	time.sleep(2)
    	print('stopped sleeping....')
        labelText.hide()
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

This post has been edited 1 times, last edit by "Amleto" (Feb 28th 2012, 4:57pm)


5

Wednesday, February 29th 2012, 5:44am

hiding the label is not the issue.

displaying the label for returnPressed event of Lineedit and clicked event of Pushbutton is the issue.

Label is not displayed when the button clicked(pressed) event or Lineedit return pressed event is in process.

6

Wednesday, February 29th 2012, 8:15am

well, it doesnt help that you hide it and show it at nearly the same time...

Source code

1
2
3
4
5
6
7
8
def mousePressEvent(self, keyEvent):
    	global labelText
    	labelText.show()

def pushed(self):
    	print('..........start to sleep...............')
    	global labelText
    	labelText.hide()
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.