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:http://www.qtcentre.org/forums/2-Qt-Programming
Thank you,
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.
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.
Re: Add Gradient to Background for QListView
vasant
no attachment found.
pls attach again
Bala
Re: Add Gradient to Background for QListView
hi
for gradient use this stylesheet
for blue color
Code:
t->setStyleSheet("background-color: qlineargradient(x1: 0.5, y1: 0.5 x2: 0.5, y2: 1, stop: 0 #6666FF, stop: 0.7 #99CCFF );");
for green color
Code:
t->setStyleSheet("background-color: qlineargradient(x1: 0, y1: 0 x2: 0, y2: 1, stop: 0 #00CD00 , stop: 0.2 #0AC92B stop: 1 #00FF33 );");
not exactly as qtcenter. but its a green gradient
hope it helps
Bala
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?.
Re: Add Gradient to Background for QListView
have u tried the mentioned stylesheet?
Quote:
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
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".
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.
Re: Add Gradient to Background for QListView
Quote:
Originally Posted by
vasant
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 :)
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.
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 )