[Qt-interest] How to add more items in QListWidget

Siddu Hallikeri siddugh at gmail.com
Mon Jan 3 06:17:15 CET 2011


Hi

No, Icon is from the local resource (I mean reading icon from the local
resource in the app).

I am unable to down load the image from this overloaded paint code.

Please let me know can we download image from this overloaded paint method,
if so please let me know to do it,

The thing is I want to show text data first and then image as it download
from the server, (between this, I want to show busy indicator while image is
downloading)

any code will be helpful.

Thanks

On Mon, Jan 3, 2011 at 10:39 AM, Abhishek <abhishekworld at gmail.com> wrote:

>
>
> On Mon, Jan 3, 2011 at 10:29 AM, Siddu Hallikeri <siddugh at gmail.com>wrote:
>
>> Hi Abhishek,
>>
>> Here is the delegate painter code
>>
>> Actually the requirement is
>>
>> I get the data from the server, after parsing I get 3 Strings, one for
>> 'title' , one for 'Description' and one string for image as URL.
>>
>> I display the title and Description, first and I down load the image from
>> the url and add it cell (like I am displaying the data (text) as I get and
>> then image)
>>
>> So I used the Custom Cell, so that I gave URL to that cell and it
>> downloads in it.
>>
>> Does the paint method will draw all the items every time is add the item ?
>>
>>
>> void ListDelegate::paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
>>
>> {
>>
>>     QRect r = option.rect;
>>
>>      //Color: #C4C4C4
>>
>>     QPen linePen(QColor::fromRgb(211,211,211), 1, Qt::SolidLine);
>>
>>      //Color: #005A83
>>
>>     QPen lineMarkedPen(QColor::fromRgb(0,90,131), 1, Qt::SolidLine);
>>
>>      //Color: #333
>>
>>     QPen fontPen(QColor::fromRgb(51,51,51), 1, Qt::SolidLine);
>>
>>      //Color: #fff
>>
>>     QPen fontMarkedPen(Qt::white, 1, Qt::SolidLine);
>>
>>      if(option.state & QStyle::State_Selected){
>>
>>         QLinearGradient gradientSelected(r.left(),r.top(),r.left(),r.height()+r.top());
>>
>>         gradientSelected.setColorAt(0.0, QColor::fromRgb(119,213,247));
>>
>>         gradientSelected.setColorAt(0.9, QColor::fromRgb(27,134,183));
>>
>>         gradientSelected.setColorAt(1.0, QColor::fromRgb(0,120,174));
>>
>>         painter->setBrush(gradientSelected);
>>
>>         painter->drawRect(r);
>>
>>          //BORDER
>>
>>         painter->setPen(lineMarkedPen);
>>
>>         painter->drawLine(r.topLeft(),r.topRight());
>>
>>         painter->drawLine(r.topRight(),r.bottomRight());
>>
>>         painter->drawLine(r.bottomLeft(),r.bottomRight());
>>
>>         painter->drawLine(r.topLeft(),r.bottomLeft());
>>
>>          painter->setPen(fontMarkedPen);
>>
>>      } else {
>>
>>         //BACKGROUND
>>
>>         //ALTERNATING COLORS
>>
>>         painter->setBrush( (index.row() % 2) ? Qt::white : QColor(252,252,252) );
>>
>>         painter->drawRect(r);
>>
>>          //BORDER
>>
>>         painter->setPen(linePen);
>>
>>         painter->drawLine(r.topLeft(),r.topRight());
>>
>>         painter->drawLine(r.topRight(),r.bottomRight());
>>
>>         painter->drawLine(r.bottomLeft(),r.bottomRight());
>>
>>         painter->drawLine(r.topLeft(),r.bottomLeft());
>>
>>          painter->setPen(fontPen);
>>
>>     }
>>
>>      //GET TITLE, DESCRIPTION
>>
>>     QIcon *ic=new QIcon(QPixmap(":/home.png"));
>>
>>     QString title = index.data(Qt::DisplayRole).toString();
>>
>>     QString description = index.data(Qt::UserRole + 1).toString();
>>
>>
>> //Icon
>>
>>      if (!ic->isNull()) {
>>
>>         //ICON
>>
>>         r = option.rect.adjusted(0, 0, -10, -10);
>>
>>         ic->paint(painter, r, Qt::AlignVCenter|Qt::AlignLeft);
>>
>>     }
>>
>> Is Icon is that image you are downloading and painting ?
>
>>
>>
>>  int imageSpace = 10;
>>
>> if(!description.isNull())
>>
>> {
>>
>>       //TItle
>>
>>     r = option.rect.adjusted(100, 0, -10, -30);
>>
>>     painter->setFont( QFont( "Lucida Grande",r.height()-30, QFont::Bold ) );
>>
>>     painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignBottom|Qt::AlignLeft, title, &r);
>>
>>
>>      //DESCRIPTION
>>
>>     r = option.rect.adjusted(100, 0, -10, -30);
>>
>>     painter->setFont( QFont( "Lucida Grande",r.height()-30, QFont::Normal ) );
>>
>>     //painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignLeft, description, &r);
>>
>>     painter->drawText(r, Qt::AlignCenter, description);
>>
>> }
>>
>>
>> And when ever you want to show  text/image normally  always check for the
> DisplayRole that the one which shows all that in normal way ,
>
>
>>
>> Thanks,
>> Siddu
>>
>> On Mon, Jan 3, 2011 at 10:08 AM, Abhishek <abhishekworld at gmail.com>wrote:
>>
>>>
>>> Can you please share the Delegate code that way We can help you more .
>>> NOTE: Please keep Qt-interest at qt.nokia.com in cc or every mail easy way
>>> is to use replay all option and reply to mail in malling list :).
>>>
>>> On Mon, Jan 3, 2011 at 7:05 AM, Siddu Hallikeri <siddugh at gmail.com>wrote:
>>>
>>>> Hi Abhishek,
>>>>
>>>> Thanks for reply
>>>>
>>>> I tried with delegates by overriding the paint method
>>>> but, view is flickring..
>>>>
>>>>
>>>> On Mon, Jan 3, 2011 at 12:18 AM, Abhishek <abhishekworld at gmail.com>wrote:
>>>>
>>>>> Why dont you try using Delegates not sure about your case but making
>>>>> new Cell every time is not a good idea ..
>>>>>
>>>>> On Sun, Jan 2, 2011 at 11:00 PM, Siddu Hallikeri <siddugh at gmail.com>wrote:
>>>>>
>>>>>>
>>>>>> Hi all,
>>>>>>
>>>>>> How to add more items in QListWidget ?
>>>>>>
>>>>>> Below is the code I am using, it gives error as "memory full" in
>>>>>> device (N8)
>>>>>>
>>>>>> void gotItem(IndividualSearchData *item)
>>>>>> {
>>>>>>
>>>>>> Cell* cell = new Cell();
>>>>>> cell->setTitle(item->m_Title);
>>>>>> cell->setDescription(item->m_ShortDescription);
>>>>>> cell->setImage(item->m_IconURL);
>>>>>>
>>>>>> connect(cell,SIGNAL(imageButtonClicked(QPixmap)),this,SLOT(previewImage(QPixmap)));
>>>>>> QListWidgetItem *dataItem= new QListWidgetItem(ui->listWidget);
>>>>>>
>>>>>> dataItem->setSizeHint(QSize(430,189));
>>>>>> ui->listWidget->addItem(dataItem);
>>>>>> ui->listWidget->setItemWidget(dataItem,cell);
>>>>>>
>>>>>> }
>>>>>>
>>>>>>
>>>>>> Cell is a sub class of of QWidget and contains three labels "title",
>>>>>> "discription" and pass url as parameter.
>>>>>>
>>>>>> The cell download the image from this url.
>>>>>>
>>>>>> The gotItem method is called for about 400-500 times(whenever we get
>>>>>> data from server)
>>>>>>
>>>>>> I checked with memory, it keeps on increasing, but how to reduce this
>>>>>> ?
>>>>>>
>>>>>> Please let me know how to achieve this.
>>>>>>
>>>>>>
>>>>>> Even I checked with 150 of items and stopped downloading image , still
>>>>>> it takes lot of memory
>>>>>>
>>>>>> Thanks in advance
>>>>>>
>>>>>> siddu
>>>>>> --
>>>>>> Siddu Hallikeri
>>>>>>
>>>>>> _______________________________________________
>>>>>> Qt-interest mailing list
>>>>>> Qt-interest at qt.nokia.com
>>>>>> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Abhishek Patil
>>>>> URL: http://thezeroth.net
>>>>> "Imagination is more important than knowledge..." -Albert Einstein
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Siddu Hallikeri
>>>>
>>>
>>>
>>>
>>> --
>>> Abhishek Patil
>>> URL: http://thezeroth.net
>>> "Imagination is more important than knowledge..." -Albert Einstein
>>>
>>
>>
>>
>> --
>> Siddu Hallikeri
>>
>
>
>
> --
> Abhishek Patil
> URL: http://thezeroth.net
> "Imagination is more important than knowledge..." -Albert Einstein
>



-- 
Siddu Hallikeri
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110103/873d7e0a/attachment.html 


More information about the Qt-interest-old mailing list