Results 1 to 6 of 6

Thread: QTableView + edit mode on mouse hover

  1. #1
    Join Date
    Jun 2013
    Posts
    7
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Question QTableView + edit mode on mouse hover

    I have been reading the star delegate sample in order to learn how to use custom widgets in a qtableview cell.

    In the sample, the edit mode is activated using a double click or a click if the item is selected, but, I would like to activate the edit mode when the mouse cursor is hover the cell containing the custom widget. QAbstractItemView has no EditTrigger for this. What is the best approach to achive this?

    Thanks

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QTableView + edit mode on mouse hover

    How are you adding the custom widget? using Delegate Painting / setIndexWidget()?

    A simple apprach is to use setIndexWidget().BTW tell somthing about the custom widget, do you need button clicks on it/combo box or just plain images etc?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jun 2013
    Posts
    7
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView + edit mode on mouse hover

    The use case is the same as the one seen in the star delegate example.

    I am using a QStyledItemDelegate for drawing the rating of the elements in my QTableView and for creating the "editor" widget. My QTableView is populated by a custom model filled with data from a data base.

    I want to achieve the same behavior used in iTunes (list view) for rating elements. If a row is selected, the user should be able to rate this element by clicking in the rating widget, the first click over the rating widget modifies the rating if the row is selected, if not, the first click selects the row. In the example this click enables the edit mode, I want to avoid this behavior.

    Thank you for your help Santosh.

  4. #4
    Join Date
    Jun 2013
    Posts
    7
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView + edit mode on mouse hover

    Finally, I have a preliminary version working.

    I have subclased QTableView, activated mouse tracking and reimplemented the mouseMoveEvent. Then using indexAt I can get the model index under the mouse cursor. If the mouse is hover a selected row and hover the my rating column I call edit.

    In my editor I have reimplemented the leaveEvent for closing the editor when the mouse cursor leaves it. I am using the mouseReleaseEvent in my editor for commiting data to my model.

  5. #5
    Join Date
    Jul 2016
    Location
    Bydgoszcz, Poland
    Posts
    2
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QTableView + edit mode on mouse hover

    Quote Originally Posted by louissmr View Post
    Finally, I have a preliminary version working.

    I have subclased QTableView, activated mouse tracking and reimplemented the mouseMoveEvent. Then using indexAt I can get the model index under the mouse cursor. If the mouse is hover a selected row and hover the my rating column I call edit.

    In my editor I have reimplemented the leaveEvent for closing the editor when the mouse cursor leaves it. I am using the mouseReleaseEvent in my editor for commiting data to my model.
    Hello,
    Could You provide me with a code sample of how You have managed to reimplement the leaveEvent?
    I have a problem with calling off the editor of my itemDelegate on mouse leaving the listView widget.
    I've managed to implement a custom widget as an editor for a custom treeView, by sub-classing the QStyledItemDelegate.
    Also, when mouse enters my sub-classed treeView (or listView) i call the editor (mousetracking(true) and re-implementation of mouseMoveEvent).
    But I still have a problem with calling off the editor, when mouse leaves the treeView . It is crucial, because only when the editor is called of, the data are saved to the model.

  6. #6
    Join Date
    Jul 2016
    Location
    Bydgoszcz, Poland
    Posts
    2
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QTableView + edit mode on mouse hover

    Ok. Finally I've done something like this:

    void MyTreeView::mouseMoveEvent(QMouseEvent *event){
    //zamiast presEvent();
    if(indexAt(event->pos()) != myPreviousIndex){
    // mousePressEvent(event);
    closePersistentEditor(myPreviousIndex);

    openPersistentEditor(indexAt(event->pos()));

    myPreviousIndex = indexAt(event->pos());

    /* qDebug() << indexAt(event->pos()).internalId() << myPreviousIndex.internalId() << indexAt(event->pos()).row() << myPreviousIndex.row();
    edit(indexAt(event->pos()));
    myPreviousIndex = indexAt(event->pos()); */
    }
    QTreeView::mouseMoveEvent(event);
    }

    void MyTreeView::leaveEvent(QEvent *event)
    {
    // setMouseTracking(false);
    closePersistentEditor(myPreviousIndex);

    qDebug() << "left treeView";
    myPreviousIndex = QModelIndex();
    emit saveToModelFromEditor();
    QTreeView::leaveEvent(event);
    }

Similar Threads

  1. Replies: 26
    Last Post: 7th January 2016, 20:26
  2. QTableView line edit clears the text on edit
    By PlasticJesus in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2015, 19:06
  3. Mouse hover issue in qt 4.7
    By qtuser123 in forum Qt Programming
    Replies: 0
    Last Post: 24th September 2012, 09:37
  4. Replies: 1
    Last Post: 11th May 2011, 12:51
  5. Hover on mouse over while dragging
    By mooreaa in forum Qt Programming
    Replies: 3
    Last Post: 6th February 2010, 10:31

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.