Results 1 to 8 of 8

Thread: How to show two icon in QTreeView

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Join Date
    Oct 2012
    Location
    Gurgaon, Haryana, India
    Posts
    15
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Post Re: How to show two icon in QTreeView

    Hi,
    i am using QItemDelegates paint method for custom delegate. My code is as following
    .h file
    Qt Code:
    1. #include <QItemDelegate>
    2. #include <QModelIndex>
    3. #include <QObject>
    4. #include <QSize>
    5. #include <QSpinBox>
    6.  
    7. class TreeViewItemDelegate : public QItemDelegate
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. TreeViewItemDelegate(QObject *parent = 0);
    13.  
    14. void paint( QPainter * painter,
    15. const QStyleOptionViewItem & option,
    16. const QModelIndex & index ) const;
    17. };
    To copy to clipboard, switch view to plain text mode 
    .cpp file
    Qt Code:
    1. TreeViewItemDelegate::TreeViewItemDelegate(QObject *parent)
    2. : QItemDelegate(parent)
    3. {
    4. }
    5.  
    6. void TreeViewItemDelegate ::paint( QPainter * painter,
    7. const QStyleOptionViewItem & option,
    8. const QModelIndex & index ) const
    9. {
    10. QString contactURI = index.model()->data(index, Qt::DisplayRole).toString();
    11. QIcon icon = qvariant_cast<QIcon>(index.model()->data(index, Qt::DecorationRole));
    12. QIcon icon2 = qvariant_cast<QIcon>(index.model()->data(index, Qt::UserRole+5));
    13.  
    14. QPixmap iconPixmap = icon.pixmap(option.decorationSize);
    15. QPixmap iconPixmap2 = icon2.pixmap(option.decorationSize);
    16.  
    17. QStyleOptionViewItem myoption = option;
    18. QStyleOptionViewItem myoption2 = option;
    19. QStyleOptionViewItem myoption3 = option;
    20. myoption.displayAlignment = Qt::AlignCenter;
    21. myoption2.decorationAlignment = Qt::AlignLeft;
    22. myoption3.decorationAlignment = Qt::AlignRight;
    23.  
    24. drawBackground(painter, myoption, index);
    25. drawDecoration(painter, myoption, myoption2.rect, iconPixmap);
    26. drawDisplay(painter,myoption, myoption.rect, contactURI);
    27. drawDecoration(painter, myoption, myoption3.rect, iconPixmap2);
    28. drawFocus(painter, myoption,myoption.rect);
    29. }
    To copy to clipboard, switch view to plain text mode 
    There is on problem that only one icon is displaying. I know i am doing something wrong, so can anyone help me to correct this code to display both icon??
    Last edited by Pardeep; 11th February 2013 at 11:09. Reason: missing [code] tags

Similar Threads

  1. Add icon to the right in a QTreeView
    By hubbobubbo in forum Qt Programming
    Replies: 3
    Last Post: 21st April 2010, 19:01
  2. QTreeView ICON
    By Raymond in forum Qt Programming
    Replies: 2
    Last Post: 28th October 2009, 02:43
  3. QPushButton - Only show the Icon
    By graciano in forum Newbie
    Replies: 9
    Last Post: 19th September 2009, 21:15
  4. QSystemTrayIcon doesn't show icon ?
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 25th January 2007, 19:17
  5. WYSIWYG html, Window show png icon mac no!
    By patrik08 in forum Qt Programming
    Replies: 10
    Last Post: 25th May 2006, 12:01

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
  •  
Qt is a trademark of The Qt Company.