Results 1 to 6 of 6

Thread: QComboBox drop list button events

  1. #1
    Join Date
    Jul 2007
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QComboBox drop list button events

    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.

  2. #2
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QComboBox drop list button events

    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.

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QComboBox drop list button events

    Quote Originally Posted by mchara View Post
    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.
    J-P Nurmi

  4. #4
    Join Date
    Jul 2007
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QComboBox drop list button events

    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.

  5. #5
    Join Date
    Jul 2007
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QComboBox drop list button events

    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.

  6. #6
    Join Date
    Jul 2007
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QComboBox drop list button events

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.