Unsolved QStyledItemDelegate display not correctly with Qt5.11.2
-
Hi everybody,
I have an display trouble with Qt5.11.2 with QStyledItemDelegate on QTableWidget,
the width of combobox take the width of content.
Display correctly with Qt5.9.6, Someone has the same problem?
-
@cfdev said in QStyledItemDelegate display not correctly with Qt5.11.2:
the width of combobox
QStyledItemDelegate
shows a combobox only for boolean data by default so I suspect you are subclassing it. could you show us your code? -
@VRonin yes
/** * @brief The itemComboStyle class */ class itemComboStyle : public QStyledItemDelegate { Q_OBJECT private: QStringList m_list; public: itemComboStyle(QStringList list, QObject *parent ) : QStyledItemDelegate(parent) { m_list = list; } // Editor on click QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& style, const QModelIndex& index) const { Q_UNUSED(style);Q_UNUSED(index); // Combobox create QComboBox* cbox = new QComboBox(parent); // Add stringsList cbox->addItems(m_list); // Set current text cbox->setCurrentText( index.data().toString() ); return cbox; } };
-
You are missing 3 methods to reimplement:
setModelData
,setEditorData
and the one that takes care of the visual bug you are having,updateEditorGeometry
QStringList m_list;
It's probably more efficient to use
QStringListModel m_list
and replacecbox->addItems(m_list);
withcbox->setModel(m_list);
cbox->setCurrentText( index.data().toString() );
This should not be part of
createEditor
, this goes intosetEditorData