Results 1 to 12 of 12

Thread: Add Gradient to Background for QListView

  1. #1
    Join Date
    Feb 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Add Gradient to Background for QListView

    Hi,

    I want to setbackground of Rows in QListView with Gradient.I am attaching the way i want,Pls have a look.
    I want exactly what we see in the qtcentre site.white background and green text on it.How can i do that?.Please help me.

    Attachment:

    Thank you,
    Last edited by vasant; 17th February 2010 at 10:53.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Add Gradient to Background for QListView

    If you have a view, then just use the delegate and paint the background yourself using the paint method. Use QLinearGradient as a brush for your painter.

  3. #3
    Join Date
    Feb 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Add Gradient to Background for QListView

    Thanks for the reply, Can you guide me bit more.....as i am new to QT.I have gone through documentation.

  4. #4
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Add Gradient to Background for QListView

    vasant
    no attachment found.
    pls attach again

    Bala

  5. #5
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Add Gradient to Background for QListView

    hi

    for gradient use this stylesheet
    for blue color
    Qt Code:
    1. t->setStyleSheet("background-color: qlineargradient(x1: 0.5, y1: 0.5 x2: 0.5, y2: 1, stop: 0 #6666FF, stop: 0.7 #99CCFF );");
    To copy to clipboard, switch view to plain text mode 

    for green color
    Qt Code:
    1. t->setStyleSheet("background-color: qlineargradient(x1: 0, y1: 0 x2: 0, y2: 1, stop: 0 #00CD00 , stop: 0.2 #0AC92B stop: 1 #00FF33 );");
    To copy to clipboard, switch view to plain text mode 

    not exactly as qtcenter. but its a green gradient

    hope it helps
    Bala
    Last edited by BalaQT; 18th February 2010 at 11:34.

  6. #6
    Join Date
    Feb 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Add Gradient to Background for QListView

    Thanks Bala for the reply,I am able to draw single color.But,How can i draw gradient to the Row Items of ListView?.

  7. #7
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Add Gradient to Background for QListView

    have u tried the mentioned stylesheet?

    t->setStyleSheet("background-color: qlineargradient(x1: 0, y1: 0 x2: 0, y2: 1, stop: 0 #00CD00 , stop: 0.2 #0AC92B stop: 1 #00FF33 );");
    its not single color, it contains three colors.
    to change different color change the hex code in stop: 0 #00CD00

    just copy and paste the stylesheet. its a green gradient with three diff green color

    Try and give ur feedback

    Bala

  8. #8
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Add Gradient to Background for QListView

    If you are using QtDesigner, right-click your QListView and select "Change styleSheet...", the select "Add Gradient" -> "background-color".

  9. #9
    Join Date
    Feb 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Add Gradient to Background for QListView

    I am getting total background as gradient.But i want only Rows with Gradient effect as we will see in QTcentre home page.
    Last edited by vasant; 19th February 2010 at 06:56.

  10. #10
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Add Gradient to Background for QListView

    Quote Originally Posted by vasant View Post
    I am getting total background as gradient.But i want only Rows with Gradient effect as we will see in QTcentre home page.
    For that you will need to use delegates. In the paint function of delegate, fill the painter rect with the linear gradient you want.
    Then call the base class function to draw over it.

    HINT : You need to draw background only for root items

  11. #11
    Join Date
    Feb 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Add Gradient to Background for QListView

    Yeah,i have done that . But i am confused how to paint particular index of ListView.I have gone through the examples in demos.but not able to get how to get the index of ListView.Kindly throw some light on this.
    Last edited by vasant; 19th February 2010 at 07:06.

  12. #12
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Add Gradient to Background for QListView

    What did you try ? You get the index in paint function of the delegate.
    QStyledItemDelegate::paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index )

Similar Threads

  1. background gradient with stylesheets
    By martinn in forum Qt Programming
    Replies: 6
    Last Post: 28th February 2010, 15:37
  2. getting gradient colors
    By venkat.godavarthi in forum Qt Programming
    Replies: 1
    Last Post: 30th October 2009, 13:36
  3. Gradient in histogram
    By giusepped in forum Qwt
    Replies: 1
    Last Post: 1st August 2009, 11:48
  4. QPainter Gradient
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2008, 12:53
  5. gradient background
    By drkbkr in forum Qt Programming
    Replies: 4
    Last Post: 30th March 2006, 16:10

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.