Re: [PyQt] Pressing enter in QLineEdit clicks QPushButton?
projetmbc wrote: Mads Ipsen a écrit : If you change 'QDialog' to 'QWidget' the problem disappears. But I have no idea why. Anybody? Best regards, Mads In the first example proposed that did not work, you can see that the button has the focus even if the cursor is in the lineedit. I think that the problem comes from here. Christophe. From the manual pages: A dialog's default button is the button that's pressed when the user presses Enter (Return). This button is used to signify that the user accepts the dialog's settings and wants to close the dialog. In other words, the first button that gets added probably gets connected up with this behaviour, which explains the behaviour. So using a QWidget is probably the correct solution: Mads -- ++ | Mads Ipsen, Ph.D, Scientific software developer| +--+-+ | QuantumWise A/S | phone: +45-29716388 | | Nørresøgade 27A | www:www.quantumwise.com | | DK-1370 Copenhagen, Denmark | email: m...@quantumwise.com | +--+-+ ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Pressing enter in QLineEdit clicks QPushButton?
Mads Ipsen schrieb: projetmbc wrote: Mads Ipsen a écrit : If you change 'QDialog' to 'QWidget' the problem disappears. But I have no idea why. Anybody? Best regards, Mads In the first example proposed that did not work, you can see that the button has the focus even if the cursor is in the lineedit. I think that the problem comes from here. Christophe. From the manual pages: A dialog's default button is the button that's pressed when the user presses Enter (Return). This button is used to signify that the user accepts the dialog's settings and wants to close the dialog. In other words, the first button that gets added probably gets connected up with this behaviour, which explains the behaviour. So using a QWidget is probably the correct solution: Yes, I think so too. Tried it, works, thanks to you both! Sibylle ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Pressing enter in QLineEdit clicks QPushButton?
Mads Ipsen wrote: rom the manual pages: A dialog's default button is the button that's pressed when the user presses Enter (Return). This button is used to signify that the user accepts the dialog's settings and wants to close the dialog. In other words, the first button that gets added probably gets connected up with this behaviour, which explains the behaviour. So using a QWidget is probably the correct solution: It is certainly not the correct solution if you really need a dialog :-) You can also call setAutoDefault(False) for all the buttons. Armando ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Pressing enter in QLineEdit clicks QPushButton?
Sibylle Koczian wrote: Hello, I've got a dialog with a QLineEdit and a QPushButton. The QLineEdit is connected to a method which takes its text and appends it to a QTextBrowser (that's taken from the first GUI example in the PyQt book by M. Summerfield). The clicked() signal of the QPushButton is connected to a method that just prints a message. The problem: this method, which should only be called by clicking the button, is called every time Enter is pressed in the QLineEdit. This happens even if the edit control isn't connected to any method. The button is next to the line edit in the form and in the tab order. With setAutoDefault(false) for this button and for the exit button which follows in tab order I can prevent this behavior, but that isn't really very comfortable. And it shouldn't be necessary, should it? All this on openSUSE with Python 2.6, PyQt 4.4.4. Thank you for help, Sibylle Can you supply a simple example that reproduces the behavior? Best regards, Mads ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Pressing enter in QLineEdit clicks QPushButton?
Mads Ipsen m...@comxnet.dk schrieb: Sibylle Koczian wrote: Hello, I've got a dialog with a QLineEdit and a QPushButton. The QLineEdit is connected to a method which takes its text and appends it to a QTextBrowser (that's taken from the first GUI example in the PyQt book by M. Summerfield). The clicked() signal of the QPushButton is connected to a method that just prints a message. The problem: this method, which should only be called by clicking the button, is called every time Enter is pressed in the QLineEdit. This happens even if the edit control isn't connected to any method. The button is next to the line edit in the form and in the tab order. With setAutoDefault(false) for this button and for the exit button which follows in tab order I can prevent this behavior, but that isn't really very comfortable. And it shouldn't be necessary, should it? All this on openSUSE with Python 2.6, PyQt 4.4.4. Thank you for help, Sibylle Can you supply a simple example that reproduces the behavior? Here it is. Tried with PyQt 4.4.4 (openSUSE) and PyQt 4.5.1 (Windows XP Prof.), same behavior. If the returnPressed() signal of the line edit is connected to the logText() method, then pressing Enter calls logText() (as it should) and then logPush() (as it shouldn't), pressing Tab doesn't call either of them. If editingFinished() is connected to logText() instead (commented out here), then pressing Enter calls both methods, as before, pressing Tab only calls logText(), but clicking on one of the buttons (self.pushtest or btFertig) calls first logText() and then the method the button is connected to and should call. So in both cases the application doesn't do what I want it to do: put the line edit text into the text browser if and only if enter (or tab) is pressed after entering something in that control, and calling the method connected to the button if and only if the button is pressed. What can I do, or what did I misunderstand? Regards Sibylle #!/usr/bin/env python # -*- coding: utf-8 -*- # test_lineeditenter.py import sys from PyQt4.QtCore import * from PyQt4.QtGui import * class Form(QDialog): def __init__(self, parent=None): super(Form, self).__init__(parent) self.lineedit = QLineEdit(uWrite something and press Enter) self.pushtest = QPushButton(uTest button) self.log = QTextBrowser() btFertig = QPushButton(uExit) layout = QVBoxLayout() layout.addWidget(self.lineedit) layout.addWidget(self.pushtest) layout.addWidget(self.log) layout.addWidget(btFertig) self.setLayout(layout) self.lineedit.selectAll() self.lineedit.setFocus() self.connect(self.lineedit, SIGNAL(returnPressed()), self.logText) #self.connect(self.lineedit, SIGNAL(editingFinished()), # self.logText) self.connect(self.pushtest, SIGNAL(clicked()), self.logPush) self.connect(btFertig, SIGNAL(clicked()), self, SLOT(close())) self.setWindowTitle(uLine edit problem) def logText(self): tx = self.lineedit.text() self.log.append(tx) self.lineedit.selectAll() self.lineedit.setFocus() def logPush(self): self.log.append(Button pressed) if __name__ == __main__: app = QApplication(sys.argv) mf = Form() mf.show() app.exec_() -- Dr. Sibylle Koczian ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Pressing enter in QLineEdit clicks QPushButton?
Sibylle Koczian wrote: Mads Ipsen m...@comxnet.dk schrieb: Sibylle Koczian wrote: Hello, I've got a dialog with a QLineEdit and a QPushButton. The QLineEdit is connected to a method which takes its text and appends it to a QTextBrowser (that's taken from the first GUI example in the PyQt book by M. Summerfield). The clicked() signal of the QPushButton is connected to a method that just prints a message. The problem: this method, which should only be called by clicking the button, is called every time Enter is pressed in the QLineEdit. This happens even if the edit control isn't connected to any method. The button is next to the line edit in the form and in the tab order. With setAutoDefault(false) for this button and for the exit button which follows in tab order I can prevent this behavior, but that isn't really very comfortable. And it shouldn't be necessary, should it? All this on openSUSE with Python 2.6, PyQt 4.4.4. Thank you for help, Sibylle Can you supply a simple example that reproduces the behavior? Here it is. Tried with PyQt 4.4.4 (openSUSE) and PyQt 4.5.1 (Windows XP Prof.), same behavior. If the returnPressed() signal of the line edit is connected to the logText() method, then pressing Enter calls logText() (as it should) and then logPush() (as it shouldn't), pressing Tab doesn't call either of them. If editingFinished() is connected to logText() instead (commented out here), then pressing Enter calls both methods, as before, pressing Tab only calls logText(), but clicking on one of the buttons (self.pushtest or btFertig) calls first logText() and then the method the button is connected to and should call. So in both cases the application doesn't do what I want it to do: put the line edit text into the text browser if and only if enter (or tab) is pressed after entering something in that control, and calling the method connected to the button if and only if the button is pressed. What can I do, or what did I misunderstand? Regards Sibylle #!/usr/bin/env python # -*- coding: utf-8 -*- # test_lineeditenter.py import sys from PyQt4.QtCore import * from PyQt4.QtGui import * class Form(QDialog): def __init__(self, parent=None): super(Form, self).__init__(parent) self.lineedit = QLineEdit(uWrite something and press Enter) self.pushtest = QPushButton(uTest button) self.log = QTextBrowser() btFertig = QPushButton(uExit) layout = QVBoxLayout() layout.addWidget(self.lineedit) layout.addWidget(self.pushtest) layout.addWidget(self.log) layout.addWidget(btFertig) self.setLayout(layout) self.lineedit.selectAll() self.lineedit.setFocus() self.connect(self.lineedit, SIGNAL(returnPressed()), self.logText) #self.connect(self.lineedit, SIGNAL(editingFinished()), # self.logText) self.connect(self.pushtest, SIGNAL(clicked()), self.logPush) self.connect(btFertig, SIGNAL(clicked()), self, SLOT(close())) self.setWindowTitle(uLine edit problem) def logText(self): tx = self.lineedit.text() self.log.append(tx) self.lineedit.selectAll() self.lineedit.setFocus() def logPush(self): self.log.append(Button pressed) if __name__ == __main__: app = QApplication(sys.argv) mf = Form() mf.show() app.exec_() If you change 'QDialog' to 'QWidget' the problem disappears. But I have no idea why. Anybody? Best regards, Mads -- ++ | Mads Ipsen, Ph.D, Scientific software developer| +--+-+ | QuantumWise A/S | phone: +45-29716388 | | Nørresøgade 27A | www:www.quantumwise.com | | DK-1370 Copenhagen, Denmark | email: m...@quantumwise.com | +--+-+ ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Pressing enter in QLineEdit clicks QPushButton?
Mads Ipsen a écrit : If you change 'QDialog' to 'QWidget' the problem disappears. But I have no idea why. Anybody? Best regards, Mads In the first example proposed that did not work, you can see that the button has the focus even if the cursor is in the lineedit. I think that the problem comes from here. Christophe. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Pressing enter in QLineEdit clicks QPushButton?
Hello, I've got a dialog with a QLineEdit and a QPushButton. The QLineEdit is connected to a method which takes its text and appends it to a QTextBrowser (that's taken from the first GUI example in the PyQt book by M. Summerfield). The clicked() signal of the QPushButton is connected to a method that just prints a message. The problem: this method, which should only be called by clicking the button, is called every time Enter is pressed in the QLineEdit. This happens even if the edit control isn't connected to any method. The button is next to the line edit in the form and in the tab order. With setAutoDefault(false) for this button and for the exit button which follows in tab order I can prevent this behavior, but that isn't really very comfortable. And it shouldn't be necessary, should it? All this on openSUSE with Python 2.6, PyQt 4.4.4. Thank you for help, Sibylle -- Sibylle Koczian ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt