PDA

View Full Version : [Bug Report?] Star Delegate Example



juarez
9th May 2013, 03:06
Hi Trolls,

I'm a great fan of Qt and I always try to build my graphical interfaces with Qt Platform.

In a new project a needed to do something close to the custom item delegation in "star delegate example" and I got frustrated as some of mouse events were not handled correctly in my editor widget subclass (it was not trivial to find that this was the problem).

I realize from debugging, even from the code of "star delegate example" and at least in my Windows 7 with Visual Studio C++ environment, that the only event that behave correctly in StarEditor.cpp was mousemoveevent(). I have no idea why it is enough to do the delegate work well alone. But the point is that no StarEditor::mousereleaseevent(), StarEditor::editingFinished(), and StarDelegate::commitAndCloseEditor() was ever called or emitted no matter what interaction I did on QTableWidget.

I googled, learned and searched a lot for two days but nothing related to this. So, almost giving up, I finally found the Qt::StrongFocus policy.

I fixed "Star Delegate Example" by changing the following code in StarDelegate.cpp:



QWidget *StarDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const

{
if (index.data().canConvert<StarRating>()) {
StarEditor *editor = new StarEditor(parent);
connect(editor, SIGNAL(editingFinished()),
this, SLOT(commitAndCloseEditor()));

// As we like to say in Brazil: the jump of the cat
editor->setFocusPolicy(Qt::StrongFocus);

return editor;
} else {
return QStyledItemDelegate::createEditor(parent, option, index);
}
}


This worked also for my project.

Could you confirm that this was a bug in "Star Delegate Example"? And if so, could you please add this in the next released docs?


Thanks and keep up the good work!


--
Juarez Paulino