Results 1 to 7 of 7

Thread: ComboBox QStyle

  1. #1
    Join Date
    Jan 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default ComboBox QStyle

    Hi,
    I'm reimplementing the style for a combobox, but can't figure out how to override the list popup that appears when you click on the arrow..

    Screenshot attached.. you can see my PE_Frame drawn around the list, but the background is still white, and i'd like to override that to black to match the rest of the box..

    I've put a breakpoint on my drawControl, drawPrimitive etc methods but they're not being triggered when the list opens (except for the PE_Frame). I can't find any clues in the Qt source for this particular part of comboboxes.. so i'm abit stuck on this one, any ideas?
    Attached Images Attached Images

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ComboBox QStyle

    Qt Code:
    1. QAbstractItemView * QComboBox::view () const
    2.  
    3. Returns the list view used for the combobox popup.
    4.  
    5. See also setView().
    To copy to clipboard, switch view to plain text mode 

    this is the view of the listbox u see after u click on the down button..u should use this view to draw ur background color..should be pretty simple

  3. The following user says thank you to talk2amulya for this useful post:

    waynew (25th July 2010)

  4. #3
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ComboBox QStyle

    to be more specific, try using

    void QWidget::setBackgroundRole ( QPalette::ColorRole role )

    on the view that u get from view()

  5. #4
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ComboBox QStyle

    Why don't you use style sheets to customize the looks of your combo box? You could do away without any coding at all.

  6. #5
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ComboBox QStyle

    i guess u chose not to do using stylesheets cuz either u hv an older version of qt..or u just didnt know u can do it other ways here is how u do using stylesheets:

    QComboBox QAbstractItemView{
    background-color: black;
    }

    for further reference: http://doc.trolltech.com/4.3/stylesheet.html

  7. #6
    Join Date
    Jan 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ComboBox QStyle

    great, thanks guys.. turned out to be the QPalette::Base colour. I missed this little snippet in the documentation:

    Qt Code:
    1. Used mostly as the background color for text entry widgets, but can also be used
    2. for other painting - such as the background of combobox drop down lists and toolbar
    3. handles. It is usually white or another light color.
    To copy to clipboard, switch view to plain text mode 

    and no i didn't know about style sheets, will definately read up on them for my next project.. i've done too much qstyle work on this one to change over

  8. #7
    Join Date
    Aug 2009
    Posts
    13
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: ComboBox QStyle

    I'm trying to use style sheets to add spaces before and after each drop down item so that it can be selected more easily with a finger in a touch screen but haven't found out how. Does anyone know what the right option is?

    Here's my stylesheet for QComboBox:

    Qt Code:
    1. color: white;
    2. border-color: white;
    3. background-color: qlineargradient(x1: 0, y1: 0, x2:0, y2: 1, stop: 0 beige, stop: 1 black);
    4. border: 1px solid white;
    5. border-radius: 3px;
    6. padding: 1px 18px 1px 3px;
    7. min-width: 6em;
    8. font: 15pt "Sans Serif";
    9. }
    10.  
    11. border: 2px solid darkgray;
    12. color: white;
    13. padding: 10px 10px 10px 10px;
    14. selection-background-color: lightgray;
    15. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by vkincaid; 11th January 2010 at 17:25.

Similar Threads

  1. Replies: 2
    Last Post: 18th March 2008, 15:38
  2. [Qt 4.3.1]A problem with combobox style
    By Tamara in forum Qt Programming
    Replies: 3
    Last Post: 19th September 2007, 10:49
  3. Fonts, Colors, and QStyle
    By Jimmy2775 in forum Qt Programming
    Replies: 1
    Last Post: 28th September 2006, 07:26
  4. Combobox Signals
    By b1 in forum Qt Programming
    Replies: 3
    Last Post: 1st August 2006, 10:21
  5. Filling combobox from database
    By Philip_Anselmo in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2006, 17:53

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.