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. [solved]Using the designer form and delegates problem
Forum Updated to NodeBB v4.3 + New Features

[solved]Using the designer form and delegates problem

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.7k 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.
  • JeroentjehomeJ Offline
    JeroentjehomeJ Offline
    Jeroentjehome
    wrote on last edited by
    #1

    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) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    // 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
    ui->RekList->setModel(m_pRekeningModel);
    
    ui->RekList->setItemDelegate(m_pCategoryDelegate);
    ui->RekList->resizeColumnsToContents();
    
    // test setting of delegate
    QAbstractItemDelegate * delTest;
    delTest = ui->RekList->itemDelegate();
    
    ui->RekList->setEditTriggers(QAbstractItemView::AllEditTriggers);
    

    }
    class CategoryDelegate : public QStyledItemDelegate
    {
    Q_OBJECT

    typedef QStyledItemDelegate SUPER;
    

    public:
    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;
    

    signals:

    public slots:

    private:
    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......

    Greetz, Jeroen

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

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

      Greetz, Jeroen

      1 Reply Last reply
      0
      • N Offline
        N Offline
        naiveal
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

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