Results 1 to 7 of 7

Thread: QItemDelegate enter event

  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Exclamation QItemDelegate enter event

    The following doesn't work with a QItemDelegate:
    Qt Code:
    1. bool ZeChatServer_delegate::editorEvent(QEvent *event,
    2. const QStyleOptionViewItem &option,
    3. const QModelIndex &index)
    4. {
    5. if (event->type() == QEvent::Enter)
    6. {
    7. std::cout << "Tac tac\n";
    8.  
    9. return true;
    10. }
    11. return false;
    12. }
    To copy to clipboard, switch view to plain text mode 

    How am I supposed to proceed to catch the enter / leave event of a QItemDelegate ?
    Thanks.

  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 enter event

    You should check for QStyle::State_MouseOver flag in QStyleOptionViewItem and set the WA_Hover attribute for the viewport to receive paint requests for hover events.

  3. The following user says thank you to wysota for this useful post:

    bunjee (18th April 2008)

  4. #3
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QItemDelegate enter event

    I did that :

    Qt Code:
    1. mListView->viewport()->setAttribute(Qt::WA_Hover, true);
    2. mListView->viewport()->setMouseTracking(true);
    3.  
    4. void ZeChatServer_delegate::paint(QPainter *painter,
    5. const QStyleOptionViewItem &option,
    6. const QModelIndex &index) const
    7. {
    8. QItemDelegate::paint(painter, option, index);
    9.  
    10. if (option.state == QStyle::State_MouseOver)
    11. {
    12. std::cout << "Tac tac\n";
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    Not working so far.

    Edit :
    Solved :
    Qt Code:
    1. if (option.state & QStyle::State_MouseOver)
    To copy to clipboard, switch view to plain text mode 
    Last edited by bunjee; 18th April 2008 at 20:19.

  5. #4
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QItemDelegate enter event

    Ok now I have a new problem:

    How am I supposed to know when the cursor has left the Item ?
    I have a problem with my button, it stays sunken when the cursor goes out of the item while clicking.

  6. #5
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QItemDelegate enter event

    I did some research and found this :

    void QAbstractItemView::entered ( const QModelIndex & index )

    unfortunately there is no "left" signal.
    Anyone ?

  7. #6
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QItemDelegate enter event

    According to JPN:
    For a QTableView you would connect to signals like:
    void QAbstractItemView::doubleClicked ( const QModelIndex & index )
    void QAbstractItemView::entered ( const QModelIndex & index )

    I don't see any particular signal for leaving an item. But of course you can save row/col or a persistent index for the previously colourized cell and uncolourize during the entered signal of another item and possibly leave event of the whole table view.
    I guess that's the direction I'll move forward to. Even if I find it unconvenient.

  8. #7
    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 enter event

    If you are only after colouring the item, why not do it like this?
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class Delegate : public QItemDelegate {
    4. public:
    5. Delegate(QObject *parent=0) : QItemDelegate(parent){}
    6. void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const {
    7. if(option.state & QStyle::State_MouseOver){
    8. painter->fillRect(option.rect, Qt::red);
    9. }
    10. QItemDelegate::paint(painter, option, index);
    11. }
    12. };
    13.  
    14. int main(int argc, char **argv){
    15. QApplication app(argc, argv);
    16. tv.viewport()->setAttribute(Qt::WA_Hover);
    17. QStandardItemModel model(8,8);
    18. tv.setModel(&model);
    19. tv.setItemDelegate(new Delegate(&tv));
    20. tv.show();
    21. return app.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Qt widget enter/leave event
    By bunjee in forum Qt Programming
    Replies: 11
    Last Post: 28th April 2014, 03:09
  2. Qt event queue overloading?
    By gct in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2008, 18:39
  3. Replies: 1
    Last Post: 16th October 2007, 22:41
  4. The event fired by the mouse click on the frame
    By Placido Currò in forum Qt Programming
    Replies: 8
    Last Post: 3rd March 2007, 09:05
  5. Workload in a QThread blocks main application's event loop ?
    By 0xBulbizarre in forum Qt Programming
    Replies: 14
    Last Post: 9th April 2006, 21:55

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.