Results 1 to 2 of 2

Thread: QTreeWidgetItem with tooltip+pixmap

  1. #1
    Join Date
    Jan 2011
    Location
    Verona(Italy)
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Question QTreeWidgetItem with tooltip+pixmap

    Hi to all, I'm using the following code to setup a tooltip text for a TreeWidgetItem:
    Qt Code:
    1. myTreeWidgetItem->setToolTip(myColumn, "My ToolTip text");
    To copy to clipboard, switch view to plain text mode 

    I would like to set a QPixmap instead of
    Qt Code:
    1. "My ToolTip text"
    To copy to clipboard, switch view to plain text mode 
    , but i can't.

    I could use a rich text to load image from resources, for example:
    Qt Code:
    1. <img src=":/images/myFileImage.png">
    To copy to clipboard, switch view to plain text mode 
    but i would mix the code above with a QPixmap dynamically generated.

    Do I have to use QMimeData?
    Any suggestions?

    Many Regards.

  2. #2
    Join Date
    Jan 2011
    Location
    Verona(Italy)
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidgetItem with tooltip+pixmap

    No answer?
    Ok, i will share my solution.

    In MyTreeWidget class:
    Qt Code:
    1. connect(this, SIGNAL(itemEntered(QTreeWidgetItem*,int)), this, SLOT(onItemEntered(QTreeWidgetItem*, int)));
    2.  
    3. void MyTreeWidget::onItemEntered(QTreeWidgetItem* nItem, int nColumn)
    4. {
    5. MyTreeWidgetItem* itemCasted = static_cast<MyTreeWidgetItem*>(nItem);
    6. static MyTreeWidgetItem* currentItem = 0;
    7. if (currentItem && (currentItem != itemCasted ))
    8. {
    9. currentItem->endTracking();
    10. }
    11. currentItem = itemCasted;
    12. currentItem->beginTracking();
    13. }
    To copy to clipboard, switch view to plain text mode 

    in MyTreeWidgetItemclass:

    Qt Code:
    1. void MyTreeWidgetItem::endTracking()
    2. {
    3. dynamicLabel.hide();
    4. }
    5.  
    6. void MyTreeWidgetItem::beginTracking()
    7. {
    8. if (dynamicLabel.isHidden())
    9. {
    10. dynamicLabel.show();
    11. currentTime = 0;
    12. maxTime = 1000;
    13. advance();
    14. }
    15. else
    16. {
    17. currentTime = 0;
    18. }
    19. }
    20.  
    21. void MyTreeWidgetItem::advance()
    22. {
    23. if (currentTime < maxTime)
    24. {
    25. currentTime += 25;
    26. QPoint newPos = QCursor::pos();
    27. newPos.setX(newPos.x() + 10);
    28. dynamicLabel.move(newPos);
    29. QTimer::singleShot(25, this, SLOT(advance()));
    30. }
    31. else
    32. {
    33. endTracking();
    34. }
    35. }
    To copy to clipboard, switch view to plain text mode 
    of course, we need to extends QObject
    Qt Code:
    1. class MyTreeWidgetItem : public QObject, public QTreeWidgetItem
    2. {
    3. Q_OBJECT
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Tooltip delays
    By drhex in forum Qt Programming
    Replies: 8
    Last Post: 15th November 2011, 22:46
  2. Replies: 5
    Last Post: 23rd September 2010, 13:58
  3. Tooltip in Qwt
    By Ankitha Varsha in forum Qwt
    Replies: 5
    Last Post: 8th December 2009, 12:07
  4. Extended Tooltip
    By aamer4yu in forum Qt Programming
    Replies: 12
    Last Post: 26th July 2008, 11:18
  5. ToolTip....
    By merry in forum Qt Programming
    Replies: 27
    Last Post: 3rd August 2007, 10:42

Tags for this Thread

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.