the simpliest way
class MyComplexEditor
: public QWidget{
Q_OBJECT
public:
{
setFocusProxy(m_spinBox);
hbl->setMargin(0);
hbl->setSpacing(0);
hbl->addWidget(m_spinBox);
hbl->addWidget(m_toolButton);
}
QSpinBox *spinBox
() const { return m_spinBox;
} QToolButton *toolButton
() const { return m_toolButton;
}
private:
};
...
{
return new MyComplexEditor(parent);
}
{
MyComplexEditor *mce = qobject_cast<MyComplexEditor *>(editor);
if (!mce)
return;
mce->spinBox()->setValue(turkish.toDouble(index.model()->data(index, Qt::EditRole).toString().remove(totalParaBirimi, Qt::CaseInsensitive)));
mce->spinBox()->selectAll();
}
}
class MyComplexEditor: public QWidget
{
Q_OBJECT
public:
MyComplexEditor(QWidget *parent = 0) : QWidget(parent)
{
m_spinBox = new QSpinBox();
m_toolButton = new QToolButton();
QHBoxLayout *hbl = new QHBoxLayout(this);
m_spinBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
m_toolButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
setFocusProxy(m_spinBox);
hbl->setMargin(0);
hbl->setSpacing(0);
hbl->addWidget(m_spinBox);
hbl->addWidget(m_toolButton);
}
QSpinBox *spinBox() const { return m_spinBox; }
QToolButton *toolButton() const { return m_toolButton; }
private:
QSpinBox *m_spinBox;
QToolButton *m_toolButton;
};
...
void MyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
return new MyComplexEditor(parent);
}
void MyDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
MyComplexEditor *mce = qobject_cast<MyComplexEditor *>(editor);
if (!mce)
return;
mce->spinBox()->setValue(turkish.toDouble(index.model()->data(index, Qt::EditRole).toString().remove(totalParaBirimi, Qt::CaseInsensitive)));
mce->spinBox()->selectAll();
}
}
To copy to clipboard, switch view to plain text mode
nothing complex, right?
Bookmarks