QItemDelegate and custom widget
hi, i subclassed QWidget as CustomWidget, and in CustomDelegate:: createEditor() i new a CustomWidget instance and return it. now once i double click the item in a view, the editor widget was created, and once i press the editor widget( a CustomWidget instance), the delegate commit data and close editor and the editor widget was destroyed. this is not our expection. i wonder how to control the editor widget's closing event, for example, click event will edit the data, and double click event will close the editor and commit data.
i'v read the star delegate in Qt's example, however, in the following code, i cannot change the close event from "release" to "double click".
:crying::(:mad:
in this example, once the mouse release, the editor was destroyed.
Code:
void StarEditor
::mouseReleaseEvent(QMouseEvent * /* event */) {
emit editingFinished();
}
//! [3]
void StarEditor
::mouseDoubleClickEvent(QMouseEvent *event
) {
emit editingFinished();
}
{
update();
}
Thanks!
Re: QItemDelegate and custom widget
Did you reimplement any event handler? Can you show us the code?
Re: QItemDelegate and custom widget
Quote:
Originally Posted by
wysota
Did you reimplement any event handler? Can you show us the code?
neither
Code:
{
if (obj == label)
{
if(event
->type
() == QEvent::MouseButtonPress) {
setChecked(!checked);
return true;
}
else if(event
->type
() == QEvent::MouseButtonDblClick) {
emit editingFinished();
return true;
}
else if (event
->type
() == QEvent::MouseButtonRelease) {
return true;
}
}
else
return true;//QObject::eventFilter(obj, event);
}
nor
Code:
void StarWidget
::mouseDoubleClickEvent(QMouseEvent* /*event*/) {
// emit editingFinished();
}
void StarWidget
::mousePressEvent(QMouseEvent * /*event*/) {
}
is working. so i don't know how to prevent the delegate close the editor when pressing the item.