PDA

View Full Version : QComboBox drop list button events



maird
10th October 2007, 20:58
Are there signals for the drop list button on a QComboBox. I'm using a QTableView with an editor delegate for a column. The delegate is a QComboBox and I'd like it to showPopup() when the QComboBox is first shown. I'd also like to detect the drop list being closed so that I can call closeEditor(). I have several parts of the necessary functionality working in crude ways but I'd like something more direct. For example:

* I can cause the list to drop when the QComboBox is displayed if I sub-class QComboBox and start a c. 200ms timer in showEvent() then have timerEvent() call showPopup() and kill the timer.
* I can call closeEditor() on activate and index change signals

I can't yet detect that the drop list is closed via the button. I'd also like a better way than the timer for getting the drop list to appear when the QComboBox is shown.

I searched the forum for QComboBox related threads and didn't find what I am looking for. I'd appreciate any ideas.

mchara
11th October 2007, 07:14
Is this comboBox editable?
if it is, you can simply create a derrived class that overrides mousePressEvent and emit a signal when widget under mouse isn't QLineEdit. If something is clicked in comboBox and it's not QLineEdit it must be an arrow button.

This sollution works fine in my application.

Take a note that if comboBox isn't set to editable it have no QLineEdit so what im doing in this case is setting comboBox to editable, but with installed eventFilter that blocks keyboardEvents, so combobox looks & works like editable but edition is blocked.

jpn
11th October 2007, 08:10
Take a note that if comboBox isn't set to editable it have no QLineEdit so what im doing in this case is setting comboBox to editable, but with installed eventFilter that blocks keyboardEvents, so combobox looks & works like editable but edition is blocked.
Perhaps you could just make the combo box editable but then make the line edit read-only. :)

maird
19th October 2007, 22:17
Sorry to take so long to respond. I killed my laptop and had to rebuild.

I tried mchara's suggestion of overriding mousePressEvent() then underMouse() idea in a QComboBox derived class. It didn't work and the behavior was unexpected. When the popup list is not visible the mousePressEvent() reaches my class. When the popup list is visible the mousePressEvent() does _not_ reach my class. That's the case I want to handle.

maird
20th October 2007, 01:16
The button on the combo box that shows or hides the list is known in the Qt source as the Arrow. I don't see how it is possible to override the handling of the arrow being clicked when the popup is visible. When the list is visible the QComboBox isn't the active widget. It's something called a QComboBoxPrivate that doesn't appear to be a child of the QComboBox. The mouse event you'd have to handle goes to the QComboBoxPrivate.

maird
20th October 2007, 19:25
No-one noticed that a read only combobox with the list automatically appearing immediately when the widget shows is pretty much a listbox. When I started with this project I used a listbox but found that implementing updateEditorGeometry() was a pain for a listbox delegate. For a combobox you only need to calculate the geometry for the line edit portion (you already have the gemometry for the table cell) and the widget calculates the geometry for the list automatically. I think I'll go back to looking at a listbox.