Results 1 to 4 of 4

Thread: MyQListBoxItem doesn't draw

  1. #1
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default MyQListBoxItem doesn't draw

    The code of the paint function is this:
    Qt Code:
    1. void MyLBItem::paint(QPainter *p)
    2. {
    3. // evil trick: find out whether we are painted onto our listbox
    4. bool in_list_box = listBox() && listBox()->viewport() == p->device();
    5.  
    6. QRect r( 0, 0, listBox()->width(), listBox()->height( ) );
    7. //p->drawText(r,Qt::AlignLeft, "new item", -1);
    8. p->drawText(10,10,"new item", -1);
    9. qDebug("Drawing text");
    10. }
    To copy to clipboard, switch view to plain text mode 

    main function is:
    Qt Code:
    1. int main(int argc, char **argv)
    2. {
    3. QApplication a(argc,argv);
    4.  
    5. QListBox lb;
    6. MyLBItem lbiE(&lb);
    7.  
    8. lb.setGeometry(100,100,200,200);
    9. lb.insertItem(&lbiE);
    10. // lbiE.SetName("item 1");
    11.  
    12. a.setMainWidget(&lb);
    13.  
    14. lb.show();
    15. // lb.repaint();
    16.  
    17. return a.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 

    when i run the app, the text doesn't show, nor the debug message. any clue?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: MyQListBoxItem doesn't draw

    Quote Originally Posted by codebehind View Post
    when i run the app, the text doesn't show, nor the debug message. any clue?
    Is MyLBItem::paint() private?
    J-P Nurmi

  3. #3
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: MyQListBoxItem doesn't draw

    paint() is protected

  4. #4
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: MyQListBoxItem doesn't draw

    After a long time...
    I've found the problem. I haven't implemented the height() and width() functions. That is well documented in the Qt documentation. It shall be as simple as RTFM. :P
    It works.

Similar Threads

  1. How do draw a frame in QListView?
    By someralex in forum Qt Programming
    Replies: 24
    Last Post: 21st December 2006, 12:56
  2. QPainter draw rounded arrow
    By xgoan in forum Qt Programming
    Replies: 1
    Last Post: 9th November 2006, 13:32
  3. Replies: 5
    Last Post: 7th November 2006, 16:01
  4. Using QGLWidget paint engine to draw regular widgtes?
    By high_flyer in forum Qt Programming
    Replies: 11
    Last Post: 9th October 2006, 13:06
  5. Drawing over content widgets? (overlay)
    By sertrem in forum Qt Programming
    Replies: 2
    Last Post: 17th January 2006, 23:18

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.