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. ComboDelegate does not display list.
Forum Updated to NodeBB v4.3 + New Features

ComboDelegate does not display list.

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 462 Views 1 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.
  • D Offline
    D Offline
    dencla
    wrote on last edited by
    #1

    I am having an issue with the comboboxdelegate, It is working in one instance of a class but not the one listed. I'm sure I'm doing something wrong, but I can't see it.

    Below is the suspect code that does not work:

    parts.h
    #ifndef PARTS_H
    #define PARTS_H
    
    #include <QMainWindow>
    #include <QtSql>
    #include <QSqlDatabase>
    #include <QMessageBox>
    #include <QPixmap>
    #include <QTableWidget>
    
    #include "cbutton.h"
    
    namespace Ui {
    class Parts;
    class QDragEnterEvent;
    class QDropEvent;
    }
    
    class Parts : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit Parts(QWidget *parent = nullptr);
        ~Parts() override;
    
    protected:
        void dragEnterEvent(QDragEnterEvent *event) override;
        void dropEvent(QDropEvent *event) override;
        void mousePressEvent(QMouseEvent *event) override;
    
        QAction *insAction;
        QAction *columnAction;
    
        void setActions(void);
        void ShowContextMenu(const QPoint &pos);
    
    signals:
        void System_Msg(QString);
    
    private slots:
        void updateTable(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>());
        void on_PatternListView_activated(const QModelIndex &index);
        void on_PatternListView_clicked(const QModelIndex &index);
        void on_TypeColumnAction(int column);
    
    private:
        Ui::Parts *ui;
        QSqlTableModel *querypatternlist;
    //    QSqlRelationalTableModel *querypatternlist;
        void SetActions(void);
        QComboBox *typeComboBox;
    
    };
    
    #endif // PARTS_H
    
    
    parts.cpp 
    
    Parts::Parts(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::Parts)
    {
        ui->setupUi(this);
    
        QString strText;
        QString message = "Parts Table Opened";
        emit System_Msg(message);
    
        querypatternlist =new QSqlTableModel(this);
    //    querypatternlist =new QSqlRelationalTableModel(this);
        querypatternlist->setTable("patternlist");
        querypatternlist->setFilter("idPart = '"+strText+"'");
        querypatternlist->setEditStrategy(QSqlTableModel::OnFieldChange);
        ui->PatternListView->resizeColumnsToContents();
        ui->PatternListView->setStyleSheet("QTableView::item::alternate{ background-color:#bfffbf; } QTableView::item {background-color:#deffde; }");
         ui->PatternListView->setModel(querypatternlist);
        querypatternlist->select();
        ui->PatternListView->hideColumn(6);
        ui->PatternListView->hideColumn(7);
    
        ui->PatternListView->setContextMenuPolicy(Qt::CustomContextMenu);
        ui->PatternListView->setDragEnabled(true);
        ui->PatternListView->setAcceptDrops(true);
        ui->PatternListView->setDropIndicatorShown(true);
        ui->PatternListView->setDefaultDropAction(Qt::CopyAction);
    
        QHeaderView *header = ui->PatternListView->horizontalHeader();
        header->addAction(columnAction);
        header->setContextMenuPolicy(Qt::ActionsContextMenu);
    
        QStringList list;
        list <<"Lead" << " Middle" << "Trail";
        ComboBoxDelegate *comboDelegate = new ComboBoxDelegate(this);
        comboDelegate->addItemList = list;
        ui->PatternListView->setItemDelegateForColumn(1,comboDelegate );
    
        setAcceptDrops(true);
    
    }
    
    

    This same code in another window displays the comboDelegate list correctly in the QSqlTableView of that window in this same application.

    Can anyone see what I might have missed.

    All the drag&drop and edit functions work correctly to this view. The other application does not use drag&drop, but this part of the code is the same.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What exactly is not working ?
      How did you implement your delegate ?

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

      D 4 Replies Last reply
      0
      • SGaistS SGaist

        Hi,

        What exactly is not working ?
        How did you implement your delegate ?

        D Offline
        D Offline
        dencla
        wrote on last edited by
        #3

        @SGaist Thanks for responding, I'm not sure what you are asking.

        The QSqlTableview is of a mysql table That is being displayed in a designer TableView ui->patternlistview. I drag a pattern name for another table of pattern names to define the pattern that I want to use in the pattern list. There is also a type field that defines how the pattern is to be used. It is this field that I am trying to use the combo delegate as a drop down selection for the field. i'm using the code above to implement that selection, however when I right click on the column field nothing happens.
        I have the same code in another instance that functions correctly. I cannot see what I am doing wrong.

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          What exactly is not working ?
          How did you implement your delegate ?

          D Offline
          D Offline
          dencla
          wrote on last edited by
          #4

          @SGaist I did find a difference between the two instances. The one that doesn't work has been promoted to CustomSqlTableView as posted below, so i removed it and now the drag&drop does not work as well as the Combo Delegate. So I promoted it back to CustomSqlTableView.

          class CustomSqlTableView : public QTableView {
          public:
              CustomSqlTableView(QWidget *parent = nullptr) : QTableView(parent) {
                  setAcceptDrops(true);
              }
          
          
          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            What exactly is not working ?
            How did you implement your delegate ?

            D Offline
            D Offline
            dencla
            wrote on last edited by
            #5

            @SGaist I have traced the debug and an instance is being initialized in both windows, but the debugger does not register the left click in the one that doesn't work, the combobox does not appear. I have made them both identical as I possibly can. If I add an action to the view that works or if I edit the field in the view that works and if I drop a value to the field that works, but when I click on the field to call the combobox dropdown no combobox.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Can you provide a minimal compilable example that shows this ?

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

              D 1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                What exactly is not working ?
                How did you implement your delegate ?

                D Offline
                D Offline
                dencla
                wrote on last edited by
                #7

                @SGaist I have partially figured out my issue. for some reason that i do not understand the first instance that was working accepted a single left click. The new instance requires a double left click. That works but is not preferable to a right double click. Is there a way to change that?

                1 Reply Last reply
                0
                • SGaistS SGaist

                  Can you provide a minimal compilable example that shows this ?

                  D Offline
                  D Offline
                  dencla
                  wrote on last edited by
                  #8

                  @SGaist Thanks it's down to the double click now. Is there a way to change it to the right click?

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Setting the edit trigger comes to mind.

                    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
                    • D dencla has marked this topic as solved on

                    • Login

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