PDA

View Full Version : QItemDelegate and custom widget



nifei
7th November 2008, 04:10
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.


void StarEditor::mouseReleaseEvent(QMouseEvent * /* event */)
{
emit editingFinished();
}
//! [3]
void StarEditor::mouseDoubleClickEvent(QMouseEvent *event)
{
emit editingFinished();
}
void StarEditor::mousePressEvent(QMouseEvent *event)
{
update();
}

Thanks!

wysota
7th November 2008, 10:49
Did you reimplement any event handler? Can you show us the code?

nifei
10th November 2008, 00:30
Did you reimplement any event handler? Can you show us the code?

neither

bool StarWidget::eventFilter(QObject *obj, QEvent *event)
{
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


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.