Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Text from a QTableView's cell shows through inline QComboBox - OSX
Forum Updated to NodeBB v4.3 + New Features

Text from a QTableView's cell shows through inline QComboBox - OSX

Scheduled Pinned Locked Moved Unsolved Qt 6
17 Posts 4 Posters 1.6k Views 2 Watching
  • 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.
  • R Offline
    R Offline
    rpadrela
    wrote on 7 May 2021, 17:03 last edited by rpadrela 5 Aug 2021, 08:34
    #1

    Hi,

    I'm seeing an issue with a QComboBox in a QTableView letting the original value of the cell showing through as if the QComboBox is behind the table's cell.

    Image of when the table's cell is initially clicked on and the QComboBox shows up although not expanded - see text showing through

    Image of when the QComboBox is expanded - fine

    Apart from this visual glitch, the QComboBox works as expected.

    Qt's version is 6.0.3.

    This is on Mac OS X 11.2.3. I haven't had the chance to test this on any other platforms.

    Thank you.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 7 May 2021, 18:16 last edited by
      #2

      Hi and welcome to devnet,

      Are you calling setCellWidget ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply 8 May 2021, 08:36
      0
      • S SGaist
        7 May 2021, 18:16

        Hi and welcome to devnet,

        Are you calling setCellWidget ?

        R Offline
        R Offline
        rpadrela
        wrote on 8 May 2021, 08:36 last edited by
        #3

        @SGaist If that's a method from the QTableWidget, then, nope. I'm not using a QTableWidget, I'm using a QTableView.

        Btw, I have other types of delegates to embed other widgets (e.g. QSpinBox) in the table and those work fine. It's just the QComboBox that seems to have this problem.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 8 May 2021, 08:42 last edited by
          #4

          Can you show the code of that delegate ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          R 1 Reply Last reply 9 May 2021, 13:37
          0
          • S SGaist
            8 May 2021, 08:42

            Can you show the code of that delegate ?

            R Offline
            R Offline
            rpadrela
            wrote on 9 May 2021, 13:37 last edited by
            #5

            @SGaist Sure.

                class ComboBoxDelegate : public QStyledItemDelegate
                {
                    Q_OBJECT
            
                public:
                    explicit ComboBoxDelegate(QObject* parent);
                    ~ComboBoxDelegate() override = default;
            
                    QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
                    void setEditorData(QWidget *editor, const QModelIndex &index) const override;
                    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
                };
            
                ComboBoxDelegate::ComboBoxDelegate(QObject* parent)
                : QStyledItemDelegate(parent)
                {
                }
            
                QWidget* ComboBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
                {
                    QComboBox* comboBox = new QComboBox(parent);
                    comboBox->setModel(new ValueListModel(index));
                    return comboBox;
                }
            
                void ComboBoxDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
                {
                    qobject_cast<QComboBox*>(editor)->setCurrentText(index.data(Qt::EditRole).toString());
                }
            
                void ComboBoxDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
                {
                    model->setData(index, qobject_cast<QComboBox*>(editor)->currentText());
                }
            

            Thank you for looking into this.

            N 1 Reply Last reply 11 May 2021, 16:24
            0
            • V Offline
              V Offline
              VRonin
              wrote on 11 May 2021, 13:59 last edited by
              #6

              Try adding:

              public:
              void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const override{
              editor->setGeometry(option.rect);
              }
              

              "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

              R 1 Reply Last reply 11 May 2021, 15:01
              0
              • V VRonin
                11 May 2021, 13:59

                Try adding:

                public:
                void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const override{
                editor->setGeometry(option.rect);
                }
                
                R Offline
                R Offline
                rpadrela
                wrote on 11 May 2021, 15:01 last edited by
                #7

                @VRonin Thanks for the suggestion. Unfortunately, it makes no difference.

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  VRonin
                  wrote on 11 May 2021, 15:07 last edited by
                  #8

                  this is very odd... do you have a custom stylesheet applyed?

                  "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

                  R 1 Reply Last reply 11 May 2021, 15:54
                  0
                  • V VRonin
                    11 May 2021, 15:07

                    this is very odd... do you have a custom stylesheet applyed?

                    R Offline
                    R Offline
                    rpadrela
                    wrote on 11 May 2021, 15:54 last edited by
                    #9

                    @VRonin Nope

                    1 Reply Last reply
                    0
                    • R rpadrela
                      9 May 2021, 13:37

                      @SGaist Sure.

                          class ComboBoxDelegate : public QStyledItemDelegate
                          {
                              Q_OBJECT
                      
                          public:
                              explicit ComboBoxDelegate(QObject* parent);
                              ~ComboBoxDelegate() override = default;
                      
                              QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
                              void setEditorData(QWidget *editor, const QModelIndex &index) const override;
                              void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
                          };
                      
                          ComboBoxDelegate::ComboBoxDelegate(QObject* parent)
                          : QStyledItemDelegate(parent)
                          {
                          }
                      
                          QWidget* ComboBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
                          {
                              QComboBox* comboBox = new QComboBox(parent);
                              comboBox->setModel(new ValueListModel(index));
                              return comboBox;
                          }
                      
                          void ComboBoxDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
                          {
                              qobject_cast<QComboBox*>(editor)->setCurrentText(index.data(Qt::EditRole).toString());
                          }
                      
                          void ComboBoxDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
                          {
                              model->setData(index, qobject_cast<QComboBox*>(editor)->currentText());
                          }
                      

                      Thank you for looking into this.

                      N Offline
                      N Offline
                      nagesh
                      wrote on 11 May 2021, 16:24 last edited by
                      #10

                      @rpadrela I feel there is some thing wrong here(not sure)

                          {
                              qobject_cast<QComboBox*>(editor)->setCurrentText(index.data(Qt::EditRole).toString());
                          }
                      

                      Why are you setting the combo box text here?
                      Is it editable comboBox?
                      Set the comboBox setCurrentIndex here. If comboBox list of elements is set through model.

                      V R 2 Replies Last reply 11 May 2021, 16:27
                      0
                      • N nagesh
                        11 May 2021, 16:24

                        @rpadrela I feel there is some thing wrong here(not sure)

                            {
                                qobject_cast<QComboBox*>(editor)->setCurrentText(index.data(Qt::EditRole).toString());
                            }
                        

                        Why are you setting the combo box text here?
                        Is it editable comboBox?
                        Set the comboBox setCurrentIndex here. If comboBox list of elements is set through model.

                        V Offline
                        V Offline
                        VRonin
                        wrote on 11 May 2021, 16:27 last edited by VRonin 5 Nov 2021, 16:27
                        #11

                        @nagesh The current code is correct.

                        from https://doc.qt.io/qt-5/qcombobox.html#currentText-prop

                        The setter setCurrentText() simply calls setEditText() if the combo box is editable. Otherwise, if there is a matching text in the list, currentIndex is set to the corresponding index.

                        "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
                        • N nagesh
                          11 May 2021, 16:24

                          @rpadrela I feel there is some thing wrong here(not sure)

                              {
                                  qobject_cast<QComboBox*>(editor)->setCurrentText(index.data(Qt::EditRole).toString());
                              }
                          

                          Why are you setting the combo box text here?
                          Is it editable comboBox?
                          Set the comboBox setCurrentIndex here. If comboBox list of elements is set through model.

                          R Offline
                          R Offline
                          rpadrela
                          wrote on 11 May 2021, 16:53 last edited by
                          #12

                          @nagesh QComboBox is not editable.

                          Could this be an issue currently affecting Mac OS X only?

                          V 1 Reply Last reply 11 May 2021, 17:32
                          0
                          • R rpadrela
                            11 May 2021, 16:53

                            @nagesh QComboBox is not editable.

                            Could this be an issue currently affecting Mac OS X only?

                            V Offline
                            V Offline
                            VRonin
                            wrote on 11 May 2021, 17:32 last edited by VRonin 5 Nov 2021, 17:32
                            #13

                            @rpadrela said in Text from a QTableView's cell shows through inline QComboBox - OSX:

                            Could this be an issue currently affecting Mac OS X only?

                            On windows, both the windows style and Fusion work correctly with this delegate.

                            Could you try adding QApplication::setStyle(QStyleFactory::create("Fusion")); after you create the QApplication in your main()? and see if you still have the problem on Fusion?

                            "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

                            R 1 Reply Last reply 12 May 2021, 07:42
                            1
                            • S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 11 May 2021, 18:18 last edited by
                              #14

                              Did you test with 6.1 ?
                              From the looks of it's indeed macOS specific. IIRC there have been several glitches in the rendering of widgets with item views.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • V VRonin
                                11 May 2021, 17:32

                                @rpadrela said in Text from a QTableView's cell shows through inline QComboBox - OSX:

                                Could this be an issue currently affecting Mac OS X only?

                                On windows, both the windows style and Fusion work correctly with this delegate.

                                Could you try adding QApplication::setStyle(QStyleFactory::create("Fusion")); after you create the QApplication in your main()? and see if you still have the problem on Fusion?

                                R Offline
                                R Offline
                                rpadrela
                                wrote on 12 May 2021, 07:42 last edited by
                                #15

                                @VRonin

                                This

                                QApplication::setStyle(QStyleFactory::create("Fusion"));
                                

                                fixes it.

                                I haven't looked into styles yet but it seems like I should. :D

                                Thank you for your help.

                                1 Reply Last reply
                                0
                                • V Offline
                                  V Offline
                                  VRonin
                                  wrote on 12 May 2021, 08:20 last edited by
                                  #16

                                  This means it's a bug in MacOS style, might be worth reporting it

                                  "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

                                  R 1 Reply Last reply 12 May 2021, 14:40
                                  0
                                  • V VRonin
                                    12 May 2021, 08:20

                                    This means it's a bug in MacOS style, might be worth reporting it

                                    R Offline
                                    R Offline
                                    rpadrela
                                    wrote on 12 May 2021, 14:40 last edited by
                                    #17

                                    @VRonin just reported it here https://bugreports.qt.io/browse/QTBUG-93731

                                    Thank you everyone for your help.

                                    1 Reply Last reply
                                    0

                                    9/17

                                    11 May 2021, 15:54

                                    • Login

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