Results 1 to 2 of 2

Thread: Reg - Subclass of QListBoxItem

  1. #1
    Join Date
    Aug 2006
    Posts
    6
    Qt products
    Qt3
    Platforms
    Windows

    Default Reg - Subclass of QListBoxItem

    I want to display some text as bold and some as normal in QListBox.

    I created subclass inheriting the QListBoxItem class.

    The code is

    Qt Code:
    1. MyListBoxItem *l_item = new MyListBoxItem(Pointer of listbox, string);
    To copy to clipboard, switch view to plain text mode 

    Here I called the subclass.

    The Subclass is as follows

    Qt Code:
    1. class MyListBoxItem : public QListBoxItem
    2. {
    3. public:
    4.  
    5. MyListBoxItem(QListBox *a_listBox, QString a_string)
    6. {
    7. l_string = a_string;
    8. l_manageUserListBox = a_listBox;
    9. };
    10.  
    11. ~MyListBoxItem()
    12. {
    13. };
    14. void paint(QPainter *a)
    15. {
    16. QPainter a_painter(l_manageUserListBox);
    17. QRect r ( 0, 0, width( listBox() ), height( listBox() ) );
    18. QFont l_font;
    19. l_font.setBold(true);
    20. a_painter.setFont(l_font);
    21. a_painter.drawText(r,Qt::AlignLeft, l_string, -1);
    22. }
    23. private:
    24. QString l_string;
    25. QListBox *l_manageUserListBox;
    26. }
    To copy to clipboard, switch view to plain text mode 

    But i didn't work. Any suggetions will be helpful.
    Last edited by wysota; 6th January 2007 at 13:45.

  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: Reg - Subclass of QListBoxItem

    The JSeries (http://www.digitalfanatics.org/e8joh...ies/index.html) implements a custom list view item for Qt 3. Perhaps you can find some inspiration there.

Similar Threads

  1. Posting custom events to a subclass of QThread
    By jpn in forum Qt Programming
    Replies: 3
    Last Post: 4th July 2006, 15:49
  2. How to subclass a control in *.ui?
    By coralbird in forum Qt Programming
    Replies: 6
    Last Post: 6th April 2006, 02:33
  3. QT4: Sorting in QTreeWidget (subclass)
    By Michiel in forum Qt Programming
    Replies: 21
    Last Post: 29th March 2006, 18:08
  4. QFrame subclass does not reparent
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 21st March 2006, 22:15
  5. accessing subclass of QListBoxText
    By jcsneaks in forum Newbie
    Replies: 9
    Last Post: 7th February 2006, 07:28

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.