Results 1 to 3 of 3

Thread: How to draw LinearGradient background for QComboBox‘s item when focused?

  1. #1
    Join Date
    Nov 2010
    Posts
    13
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to draw LinearGradient background for QComboBox‘s item when focused?

    Hi, guys:

    I want to draw a LinearGradient background for QCombobox item when item was focused.

    I can't use CSS do it.

    Now I use the code like this: but it seems like that it LinearGradiented for all items as one;
    Qt Code:
    1. QLinearGradient linearGradient2(0, 0, 0, 100);
    2. linearGradient2.setColorAt(0, QColor(132, 132, 132, 0));
    3. linearGradient2.setColorAt(0.96, QColor(132, 132, 32, 255));
    4.  
    5. p.setBrush(QPalette::Highlight, QBrush(linearGradient2));
    6. this->setPalette(p);
    To copy to clipboard, switch view to plain text mode 

    Thanks a lot!


    Added after 15 minutes:


    The Qt deal with the 1st item, 2nd .. .. as a pic. I just want to do each item like the 1st one.
    1:

    2:

    3:
    Last edited by zimang; 2nd December 2010 at 10:30.

  2. #2
    Join Date
    Mar 2008
    Location
    Marslev, Denmark
    Posts
    31
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: How to draw LinearGradient background for QComboBox‘s item when focused?

    It sounds like you need to write a QStyle subclass for this. In there, you can paint the widget in any way you want. For all other widgets and parts, you can let the base class handle it.
    Bo Thorsen, Viking Software
    Qt applications on Linux and Windows

  3. #3
    Join Date
    Nov 2010
    Posts
    13
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to draw LinearGradient background for QComboBox‘s item when focused?

    So it means I can't implement it by QPalette? I repaint the label by paintEvent(), but can't repaint the popup menu.

Similar Threads

  1. Draw line with inverted background color
    By viswanath in forum Qt Programming
    Replies: 4
    Last Post: 12th November 2011, 04:57
  2. Draw background of custom widget
    By lumiss in forum Qt Programming
    Replies: 0
    Last Post: 24th August 2010, 10:33
  3. Replies: 1
    Last Post: 25th June 2010, 19:31
  4. Draw transparent SVG in Background of Widget
    By soul_rebel in forum Qt Programming
    Replies: 0
    Last Post: 28th October 2008, 21:44
  5. Replies: 2
    Last Post: 1st August 2008, 17:58

Tags for this Thread

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.