Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QStyledItemDelegate display not correctly with Qt5.11.2
Forum Update on Monday, May 27th 2025

QStyledItemDelegate display not correctly with Qt5.11.2

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 601 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • cfdevC Offline
    cfdevC Offline
    cfdev
    wrote on last edited by
    #1

    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?

    VRoninV 1 Reply Last reply
    0
    • cfdevC cfdev

      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?

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @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?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • cfdevC Offline
        cfdevC Offline
        cfdev
        wrote on last edited by
        #3

        @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;
           }
        };
        
        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          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( index.data().toString() );

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

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved