Results 1 to 7 of 7

Thread: KLed in a list view

  1. #1
    Join Date
    Jul 2006
    Location
    Cagliari - Sardinia - Italy
    Posts
    26
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Question KLed in a list view

    Hi
    Is it possible to put a generic QWidget into a Column of QListViewItem?

    I want a list view where each item is composed by two colimn: a string and a KLed. I have thought to use a pixmap, but if I could use KLed is better . Some Idea?

    Thanks
    Last edited by villy; 9th August 2006 at 09:26.

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: KLed in a list view

    I would say that it cannot be done easily. A pixmap would be the most straight forward method, also sub-classing QListViewItem is a possibility.

  3. #3
    Join Date
    Aug 2006
    Location
    istanbul, turkey
    Posts
    42
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: KLed in a list view

    qlistviewitem does not support adding widgets in it. Rather you may override its paintEvent method. Within paintEvent method you could draw your own widgets. if you look into qt's source files they did similar to build a list view item with check box support. But pixmap is easier than all.

  4. #4
    Join Date
    Jul 2006
    Location
    Cagliari - Sardinia - Italy
    Posts
    26
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: KLed in a list view

    Tanks a lot!
    I thought that it wasn't so easy to do without pixmap...

  5. #5
    Join Date
    Aug 2006
    Location
    istanbul, turkey
    Posts
    42
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: KLed in a list view

    it's not as much hard. i'll post you a progress bar within listviewitems.

    you need to subclass listviewitem.
    overriding of paintCell method is enough i thing.

    assume that SomeListViewItem is subclass of QListViewItem
    Qt Code:
    1. void SomeListViewItem::paintCell( QPainter *p, const QColorGroup &cg,
    2. int column, int w, int alignment )
    3. {
    4. QListViewItem::paintCell( p, cg, column, w, alignment );
    5.  
    6. QColor gray(223, 221, 244);
    7. QColor white(255, 255, 255);
    8. QColor textColor(255, 0, 0);
    9.  
    10. double wGray = (double)m_iSinyalSeviyesi * w / 100;
    11. double wWhite = (double)w - wGray;
    12.  
    13. // draw for column number 3 only
    14. // let listview draw for other columns
    15. if (column == 3) {
    16. p->setBrush(gray);
    17. p->drawRect(0, 5, (int)wGray, 32);
    18. p->setBrush(white);
    19. p->drawRect(wGray, 5, (int)wWhite, 32);
    20. p->setPen(textColor);
    21. p->drawText(w/2-10, height()/2+5, QString(s));
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 9th August 2006 at 13:29. Reason: added code tags

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: KLed in a list view

    Quote Originally Posted by hayati
    i'll post you a progress bar within listviewitems.
    For a pixmap all you need is QListViewItem::setPixmap().

  7. #7
    Join Date
    Jul 2006
    Location
    Cagliari - Sardinia - Italy
    Posts
    26
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: KLed in a list view

    thanks hayati! You've given me a very good example

    Now I try to do it .

    Thanks a lot!

Similar Threads

  1. Drag and drop items in view to sort order
    By Big Duck in forum Qt Programming
    Replies: 1
    Last Post: 25th May 2006, 19:43
  2. Replies: 1
    Last Post: 2nd May 2006, 21:11
  3. Model - View Programming doubt.
    By munna in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2006, 13:01
  4. Replies: 6
    Last Post: 20th April 2006, 10:23
  5. Rubberband painting on multiselection in a list view
    By SkripT in forum Qt Programming
    Replies: 10
    Last Post: 19th March 2006, 11:13

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.