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?
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.
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.
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.
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);
}
Bookmarks