Hi all ,
I am using QlistWidget icon along with text as iems, that icon is comming in left side,
I need another icon in rightside of the text? how can we draw icon within QListWidget?
please help me.
Thanks
Rajesh.S
Hi all ,
I am using QlistWidget icon along with text as iems, that icon is comming in left side,
I need another icon in rightside of the text? how can we draw icon within QListWidget?
please help me.
Thanks
Rajesh.S
- subclass QItemDelegate
- reimplement QItemDelegate::paint()
- calculate sufficient areas for decoration, check, etc.
- call each protected QItemDelegate::draw*() with calculated areas so that QItemDelegate::drawDecoration() ends up called twice; once with original icon and second time with icon being drawn on the right
J-P Nurmi
rajeshs (27th June 2007)
Thank you for your reply , I am beginer to Qt, If you give some tips to how to use QItemDelegate, it will realy helpful to me.
Thanks
Rajesh.S
I was thinking of something like this. Keep in mind that the following snippet was written on the fly for demonstration purposes and is missing a whole lot of checks for valid values (QVariant::isValid()) etc.
Qt Code:
{ public: ... { // calculate suitable area for text (excluding decorations) // calculate suitable area for decoration on the left // calculate suitable area for decoration on the right // draw 'em drawBackground(painter, option, index); drawDecoration(painter, option, decoration1Rect, pixmap1); drawDecoration(painter, option, decoration2Rect, pixmap2); drawDisplay(painter, option, displayRect, text); drawFocus(painter, option, displayRect); } }; // usage: listWidget->setItemDelegate(new MyItemDelegate(listWidget));To copy to clipboard, switch view to plain text mode
J-P Nurmi
Thank you for your valuable answer,
I got idea about item delegate,and how to use this delegate,
How can we pass second image to our list using this delegate,
Thanks
Rajesh.S
Last edited by rajeshs; 27th June 2007 at 05:28.
Hello Sir,
I am using the following code to set image as list item,
using itemdelegate how can i pass second image
Please help me,
QString filen(":/resources/designer.png");
QListWidget listwidget;
QIcon icon(filen);
for(int i=0;i<l5.size();i++)
{
//populating into listwidget by text and image1
QListWidgetItem *item = new QListWidgetItem(icon,i,listwidget);
item->setTextAlignment(Qt::AlignHCenter);
item->setFont(fontSplitter3);
}
thanks
Rajesh.S
I am using QT 4.2 which header file i have to use for
calcDisplayRect() and calcDecorationRect()
Thanks
Rajesh.S
The example snippet above draws the ordinary icon (Qt::DecorationRole) on the left and a custom icon (Qt::UserRole) on the right:
Qt Code:
listWidgetItem->setIcon(icon1); // same as setData(Qt::DecorationRole, QVariant::fromValue(icon1))To copy to clipboard, switch view to plain text mode
These ones you are supposed to write by yourself. :)
J-P Nurmi
Hello sir,
Thank you for your reply,Is it possible to use same itemdelegate for 2 different listwidgets?
Thaks
Rajesh.S
I am using itemdelegate for Qlistwidget and In item delegate,i am using painting to display icons and text as follows ,
if any other window pops up above this list , the painting in the list are faded away,
How can we prevent this,
My code in item delegate,
painter->drawPixmap(MyDelegate::x,MyDelegate::y,pixmap1) ;
painter->drawText(x+30,y+10,text);
if(text==" 11 Esig")
painter->drawPixmap(x+304,y,pixmap2);
Here x and y are coordinates,
please help me
Yes, it is. Use QAbstractItemView::setItemDelegate() as usual.
J-P Nurmi
I used same item delegate for 2 listwidgets if i do that 2 listwidgets are comming empty.
and if any dialog pops up above to listwidget all items are faded away?
How can we handel this? Please help me!
Thaks
Rajesh.S
Geometry of painted item is passed in the style option. What are MyDelegate::x and MyDelegate::y? What's wrong with the approach I presented above?
J-P Nurmi
Hello sir,
How to get geometry
Sorry, I didn't get how to get geometry of painting item, So i used my own points to paint the items that x and y are my points, How can we get geometry from style option and what is style option ? Plese help me.
Thaks for your response,
Rajesh,S
A style option is used to pass information on how to render the corresponding item. A QStyleOptionViewItem is passed as second parameter to QItemDelegate::paint() (see the example in paint() docs). Use QStyleOption::rect to get the geometry.
J-P Nurmi
Can any one give me idea for the definition of this function plz
Qt Code:
calcDecorationRect(pixmap1, Qt::AlignLeft);To copy to clipboard, switch view to plain text mode
i also needed to display same type of view.
As i am new user in qt so thats why i am not getting any idea how to write this function's definition.
What do you think this function is supposed to do? How is its result used? What have you tried so far?i am not getting any idea how to write this function's definition.
May be this function is used for the alignment of Icons with respect to rect (item's Rect)
Yes, so how have you tried to implement it? If you want the item to look like this: [Icon1][Item text][Icon2] how would you determine the size and position of the [Icon] rectangles?May be this function is used for the alignment of Icons with respect to rect (item's Rect)
I'm not going to write the code for you. You have to make an attempt to do it yourself first, and if you fail, post the code you tried and we will help you get it right.
Bookmarks