Results 1 to 7 of 7

Thread: QStyledItemDelegate crash

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2011
    Posts
    79
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QStyledItemDelegate crash

    I have a simple list to show list of plugins in my program. To customize it i use delegate class derived from QStyledItemDelegate.
    The code:
    Qt Code:
    1. class PluginListDelegate : public QStyledItemDelegate
    2. {
    3. public:
    4. PluginListDelegate();
    5. void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    6. QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index ) const;
    7. private:
    8. QFont line1;
    9. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. PluginListDelegate::PluginListDelegate() :
    2. line1("Tahoma",10,QFont::Bold,false)
    3. {
    4.  
    5. }
    6. void PluginListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    7. {
    8. QStyledItemDelegate::paint(painter,option,index);
    9. ...
    10. ...
    11. }
    12.  
    13. QSize PluginListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
    14. {
    15. int width = 0,height = 0;
    16. QFontMetrics fm1(line1); // <-- crash here
    17. height = fm1.height() + 20;
    18. width = fm1.width(name) + 20;
    19. return QSize(width,height);
    20. }
    To copy to clipboard, switch view to plain text mode 

    Really don't understand what I do wrong.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QStyledItemDelegate crash

    What is the actual backtrace?

Similar Threads

  1. little problem with QStyledItemDelegate
    By Qiieha in forum Qt Programming
    Replies: 1
    Last Post: 26th November 2012, 09:21
  2. Replies: 1
    Last Post: 19th June 2012, 20:20
  3. QTreeView & QStyledItemDelegate
    By mentalmushroom in forum Qt Programming
    Replies: 0
    Last Post: 29th September 2011, 07:57
  4. Custom QStyledItemDelegate
    By Berryblue031 in forum Qt Programming
    Replies: 0
    Last Post: 2nd March 2011, 10:32
  5. QStyledItemDelegate and QStyle::State_MouseOver
    By moti.lahiani in forum Qt Programming
    Replies: 0
    Last Post: 19th January 2011, 06:36

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.