ComboDelegate does not display list.
-
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.
-
Hi,
What exactly is not working ?
How did you implement your delegate ? -
@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. -
@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); }
-
@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.
-
Can you provide a minimal compilable example that shows this ?
-
@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?
-
Setting the edit trigger comes to mind.
-