Results 1 to 2 of 2

Thread: QItemDelegate clickable icon

  1. #1
    Join Date
    Apr 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QItemDelegate clickable icon

    I draw a text and the icon using QItemDelegate. Any ideas how can I make the icon clickable, like mouse over on specific rect to show the mouse hand and once clicked there emit some action.

    Could you point me to some good direction please ?

    Qt Code:
    1. virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3. if ( option.state & QStyle::State_Selected )
    4. painter->fillRect(option.rect, option.palette.highlight());
    5.  
    6. else if ( option.state & QStyle::State_MouseOver )
    7. painter->fillRect(option.rect, option.palette.highlight());
    8.  
    9. QPixmap pixmap(":icons/icon.png");
    10. QRect iconRect = option.rect;
    11.  
    12. iconRect.setTop( iconRect.top() );
    13. iconRect.setLeft( iconRect.width() );
    14.  
    15. painter->drawPixmap(QPoint(iconRect.left(), iconRect.top()), pixmap);
    16.  
    17. QRect textRect = option.rect;
    18. QString text = qvariant_cast<QString>(index.data(Qt::DisplayRole));
    19. painter->drawText( textRect, text );
    20. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QItemDelegate clickable icon

    You need to handle events within QAbstractItemDelegate::editorEvent().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Clickable URL in QMessageBox?
    By martinb0820 in forum Qt Programming
    Replies: 5
    Last Post: 23rd March 2012, 04:45
  2. QLabel clickable
    By bnilsson in forum Newbie
    Replies: 3
    Last Post: 29th July 2009, 08:50
  3. Clickable weblink
    By bnilsson in forum Qt Programming
    Replies: 6
    Last Post: 23rd June 2009, 17:13
  4. Clickable text?
    By hkvm in forum Qt Programming
    Replies: 2
    Last Post: 27th September 2008, 21:49
  5. Clickable Qlabel
    By lewis in forum Qt Programming
    Replies: 11
    Last Post: 4th June 2008, 10:39

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.