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. Black list of QCombobox items

Black list of QCombobox items

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 2 Posters 3.8k 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.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by
    #4

    Is the list of options in the combobox fixed or does it change from cell to cell?

    "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
    • K Offline
      K Offline
      Kaluss
      wrote on last edited by
      #5

      For each row is different.
      This is a product list which has to set different label.

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #6

        How does each row know what list to show?

        "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
        • K Offline
          K Offline
          Kaluss
          wrote on last edited by Kaluss
          #7

          From configuration.
          It's a global object.

          For each combobx the list of items will be the same, but which item is set it depends on configuration.
          Each row represents one product from configuration.

          VRoninV 1 Reply Last reply
          0
          • K Kaluss

            From configuration.
            It's a global object.

            For each combobx the list of items will be the same, but which item is set it depends on configuration.
            Each row represents one product from configuration.

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

            @Kaluss said in Black list of QCombobox items:

            For each combobx the list of items will be the same

            That's what I wanted to know

            #include <QStringListModel>
            #include <QComboBox>
            #include <QStyledItemDelegate>
            class ComboDelegate : public QStyledItemDelegate{
                Q_DISABLE_COPY(ComboDelegate)
            public:
                ComboDelegate(QObject* parent = Q_NULLPTR)
                    : QStyledItemDelegate(parent)
                    , m_options(new QStringListModel(this))
                {}
                QStringList options() const {return m_options->stringList();}
                void setOptions(const QStringList& opt){
                    m_options->setStringList(opt);
                }
                virtual QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE{
                    Q_UNUSED(option);
                    Q_UNUSED(index);
                    QComboBox* editor = new QComboBox(parent);
                    editor->setModel(m_options);
                    return editor;
                }
                virtual void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE{
                    QComboBox* cbEditor = qobject_cast<QComboBox*>(editor);
                    Q_ASSERT(cbEditor);
                    cbEditor->setCurrentIndex(cbEditor->findText(index.data().toString()));
                }
                virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const Q_DECL_OVERRIDE{
                    QComboBox* cbEditor = qobject_cast<QComboBox*>(editor);
                    Q_ASSERT(cbEditor);
                    model->setData(index,cbEditor->currentText());
                }
            private:
                QStringListModel* m_options;
            };
            

            "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
            3
            • K Offline
              K Offline
              Kaluss
              wrote on last edited by
              #9

              Hi,
              I get the error:
              qt has no member named 'stOptions'.

              Its shouldn't be there just options?

              If I change it to options I get:
              error: no matching function for call to 'ComboDelegate::options(QStringList&)'
              case 0: _t->options(reinterpret_cast< QStringList>(_v)); break;
              ^

              1 Reply Last reply
              0
              • VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #10

                I updated the code above to make it more efficient. how are you using 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

                1 Reply Last reply
                1
                • K Offline
                  K Offline
                  Kaluss
                  wrote on last edited by
                  #11

                  this->m_tableview_main->setItemDelegateForColumn(4, new ComboDelegate);

                  But I have the same problem as above.
                  The list of available items is black.

                  What I have to do show editor permanently not only at edition mode?

                  VRoninV 1 Reply Last reply
                  0
                  • K Kaluss

                    this->m_tableview_main->setItemDelegateForColumn(4, new ComboDelegate);

                    But I have the same problem as above.
                    The list of available items is black.

                    What I have to do show editor permanently not only at edition mode?

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

                    @Kaluss said in Black list of QCombobox items:

                    What I have to do show editor permanently not only at edition mode?

                    reimplement paint() on the delegate.

                    Before I get into it. Are you 100% adamant you don't set a stylesheet anywhere in the tableView or the widgets that are in parental relationship to 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

                    1 Reply Last reply
                    2
                    • K Offline
                      K Offline
                      Kaluss
                      wrote on last edited by
                      #13

                      Hi,
                      I found the reason. But it's not completely clear for me.
                      It was:
                      this->m_tableview_main->setStyleSheet("background-color:transparent;");

                      Anyway, thanks for your help and examples.
                      It helped me much.

                      BR/T

                      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