how to execute a QCombobox Pyqt6 cursor output method
-
@Jbone73 said in how to execute a QCombobox Pyqt6 cursor output method:
QCombobox
Subclass it and override https://doc.qt.io/qt-5/qwidget.html#focusOutEvent
-
Hello everybody,
I'm sorry for my delay, I tested jsulm's post and followed the instructions. It works but I have a little presentation problem. The combobox cursor does not delete itself and I end up with another cursor on the other fields.
My code :
class MainWindow(QMainWindow): def __init__(self): super().__init__() frame = QtWidgets.QFrame(self) qc == ComboBox(frame) qc.focusOutEvent() class ComboBox(QComboBox): def focusOutEvent(self, event=QFocusEvent): pass
Do you have any idea about this problem?
Thank you in advance.
-
@Jbone73 said in how to execute a QCombobox Pyqt6 cursor output method:
Do you have any idea about this problem?
Yes, you should also call the base class focusOutEvent in your focusOutEvent implementation.
-
Agreed ! Thank you ! I'm new to Qt and Python, I must admit I had a hard time understanding what you're asking to do.
Do I have to call the QFocusEvent class in the QCombobox class?
I'm sorry to ask so many questions but this is really new to me.
Thank you in advance.
-
@jsulm
Thank you (sorry! I keep telling you but help is always useful, especially when you're just starting out), so I tried but I have a problem with the focusOutEvent method, which I can't seem to figure out the meaning of or event = QFocusEvent.The error is:
TypeError: focusOutEvent(self, QFocusEvent): argument 1 has unexpected type 'PyQt6.sip.wrappertype'Thank you for everything and if you don't mind and if it's not too long, would you be able to explain to me? I admit that I swim a little.
-
Hi,
@Jbone73 said in how to execute a QCombobox Pyqt6 cursor output method:
@jsulm
This is the one you shared with me, I note it below:class ComboBox(QComboBox): def focusOutEvent(self, event=QFocusEvent): super().focusOutEvent(event)
What about ?
class ComboBox(QComboBox): def focusOutEvent(self, event): super().focusOutEvent(event)
If you want type hints:
class ComboBox(QComboBox): def focusOutEvent(self, event: QFocusEvent) -> None: super().focusOutEvent(event)
-
@SGaist
Hello !
I don't understand ??If I use your code :
class ComboBox(QComboBox): def focusOutEvent(self, event: QFocusEvent) -> None: super().focusOutEvent(event)
Or
class ComboBox(QComboBox): def focusOutEvent(self, event): super().focusOutEvent(event)
I have messages of errors and it does not work, on the other hand, if I put:
class ComboBox(QComboBox): def focusOutEvent(self, event=QFocusEvent): print('ok')
I do not have problem anymore, it works but not correctly.
The cursor of the combobox remains active when it takes the focus and I meet with another focus on other Widgets.I do not understand why this does not work correctly???
-
Can you provide a minimal complete script to reproduce this behaviour ?