Nominate our 2022 Qt Champions!

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.
    QStyledItemDelegate display trouble

    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
    	QStringList m_list;
       itemComboStyle(QStringList list, QObject *parent ) : QStyledItemDelegate(parent) {
    		m_list = list;
    	// Editor on click
       QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& style, const QModelIndex& index) const {
    	   // Combobox create
    	   QComboBox* cbox = new QComboBox(parent);
    	   // Add stringsList
    	   // Set current text
    	   cbox->setCurrentText( );
    	   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 replace cbox->addItems(m_list); with cbox->setModel(m_list);

    cbox->setCurrentText( );

    This should not be part of createEditor, this goes into setEditorData

Log in to reply