Important: Please read the Qt Code of Conduct -

[solved]Using the designer form and delegates problem

  • Hi people,
    Just for fun I'm writing a small program that is able to read in a file and display it in a QTableView. Very easy and simple.
    For editing I tried to use delegates (QcomboBox widget as editor). In a simple tutorial it all worked fine and my overwritten virtual functions are called as should. When double clicked the view it started the combobox editor etc.
    To get the delegate into my program (I used designer to setup the mainwindow) it doesn't work when double clicking the items.
    It does call the constructor of my delegate class, but no overwritten virtual functions are called.
    Are there special things to look at when using the designer way of constructing the mainwindow???

    Below are my delegate and constructor of my mainwindow:
    @MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)

    // Define "open" command
    ui->actionOpen->setStatusTip(tr("Open an existing file"));
    connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(OpenFile()));
    // Define "save" command
    ui->actionSave->setStatusTip(tr("Save the current data to a file"));
    connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(SaveFile()));
    connect(ui->actionExit, SIGNAL(triggered()), this, SLOT(close()));
    // construct class for holding data
    m_pRekeningData = new MyRekData;
    // Construct the model to use and give the pointer to the data
    m_pRekeningModel = new MyRekModel(m_pRekeningData, this);
    m_pCategoryDelegate = new CategoryDelegate(this);
    // Set corresponding model on view
    // test setting of delegate
    QAbstractItemDelegate * delTest;
    delTest = ui->RekList->itemDelegate();

    class CategoryDelegate : public QStyledItemDelegate

    typedef QStyledItemDelegate SUPER;

    explicit CategoryDelegate(QObject *parent = 0);

    QWidget * createEditor(QWidget *parent,
                           const QStyleOptionViewItem &option,
                           const QModelIndex &index) const;
    void setEditorData(QWidget *editor,
                       const QModelIndex &index) const;
    void setModelData(QWidget *editor,
                      QAbstractItemModel *model,
                      const QModelIndex &index) const;
    void updateEditorGeometry(QWidget *editor,
                              const QStyleOptionViewItem &option,
                              const QModelIndex &index) const;


    public slots:

    QStringList m_CategoryList;
    When debuggin the delTest variable even gives the correct address of the delegate pointer constructed.

    Please help, because I thought I understood it a bit, but got lost now again......

  • Fixed it, Never ever forget the flags function in the model!!

  • How did you fixed it?
    [quote author="Jeroentje@home" date="1356266986"]Fixed it, Never ever forget the flags function in the model!!

Log in to reply