Results 1 to 8 of 8

Thread: Custom QComboBox

  1. #1
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Custom QComboBox

    Hi,
    I have to implement a custom combo box where the popup is something like a dialog which lists the combo items and has Ok/Cancel button to conform or reject the selected item...any suggestion how to easily implement it?
    Alternatively, it's more easy to implement the same behaviour (Ok/Cancel button too) using a qpushbutton?

  2. #2
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom QComboBox

    It is probably possible to do but you will have 2 inherit the QComboBox and rewrite a few events (example on selection don't close but wait for ok button)
    I think it is easyer to just add you're own view see QComboBox then explicitly the setView()

  3. #3
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Custom QComboBox

    Quote Originally Posted by StrikeByte View Post
    It is probably possible to do but you will have 2 inherit the QComboBox and rewrite a few events (example on selection don't close but wait for ok button)
    I think it is easyer to just add you're own view see QComboBox then explicitly the setView()
    Ok...I may be wrong, but doing as suggested by you I don't have a control of the selected item by Ok/cancel buttons...unfortunately as requirement I have to convert from a standard combo box to a drop-down list controlled in selection by ok/cancel buttons.

  4. #4
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Custom QComboBox

    Hi,

    I'd rather deal with positioning than customizing QComboBox. I mean I created another little frame which owns a OK & Cancel buttons on it and set it's position when I open the combobox. When I close the combobox I'd just set it's visiblity to false.

  5. #5
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Custom QComboBox

    Quote Originally Posted by zgulser View Post
    Hi,

    I'd rather deal with positioning than customizing QComboBox. I mean I created another little frame which owns a OK & Cancel buttons on it and set it's position when I open the combobox. When I close the combobox I'd just set it's visiblity to false.
    In order to do this...have you reimplemented the QComboxBox::showPopup function? How do you associate the behaviour of your frame with the standard qcombox functions (i.e. activated/currentIndexChanged signals, currentIndex/setCurrentIndex functions)?

  6. #6
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Custom QComboBox

    Hi again,

    You don't need to do extra work to associate them. When you press the OK or Cancel button, just check which item is checked/or not checked in the combobox and act accordingly.
    (I assumed your items in the combobox are checkable since you want to reject or accept it through OK/Cancel buttons by the way)

    If you wanted to point out this is not the correct way, I can agree with you but may take less time than struggling with subclassing.

  7. #7
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom QComboBox

    Quote Originally Posted by fruzzo View Post
    Ok...I may be wrong, but doing as suggested by you I don't have a control of the selected item by Ok/cancel buttons...unfortunately as requirement I have to convert from a standard combo box to a drop-down list controlled in selection by ok/cancel buttons.
    You can add your own view (with an ok and cancel button) by using setView (i don't know if it works)

    Maybe another option is to make an inheritance of a QLineEdit and add a widget. you can trigger the widget on a click event on the lineedit
    i've made a small example of the lineedit type (the widget still opens in the wrong place, but its to get an idea) custombox.zip
    Last edited by StrikeByte; 5th June 2012 at 10:19.

  8. #8
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Custom QComboBox

    Well at the end I've customized my combobox pop showing the standard combobox list view in a dialog with Ok/Cancel like requested but I've another question...how can I resize my dialog to show all list view items without a vertical scolling?

Similar Threads

  1. Custom QComboBox or how to use Qt icons in widgets
    By ScabrusMantra in forum Qt Programming
    Replies: 1
    Last Post: 23rd March 2011, 18:34
  2. Some QComboBox and custom QValidator background
    By frankiefrank in forum Newbie
    Replies: 9
    Last Post: 9th March 2011, 15:11
  3. custom display in a QComboBox
    By scarleton in forum Qt Programming
    Replies: 2
    Last Post: 3rd September 2010, 22:13
  4. Custom Model? Custom View? Custom Delegate?
    By Doug Broadwell in forum Newbie
    Replies: 4
    Last Post: 11th February 2010, 20:23
  5. QComboBox Custom Widget has missing designer properties
    By vieraci in forum Qt Programming
    Replies: 5
    Last Post: 9th December 2009, 13:30

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.