Important: Please read the Qt Code of Conduct -

Special delegate for QTableView

  • Hello!
    A general problem is as follows:
    There is a database table that has a relationship with another on the key. Since the connected table can be very large, using ComboBox to the data from the connected table is not very convenient. Decided to do that when you click on the cell context, it could push a button and there was a connected table.
    Actually there is the realization of this idea or something like that can be replaced?

    Thank you.
    Pardoned for my english.

  • I'm afraid, I know no such implementation that can be used.

    But you can create your own delegate and implement it, should not be a too big problem. But you should search dev net for delegate problems, there was a discussion about delegates opening a window which might lead to a problem. And there were also ideas for a solution...

  • If the amount of data is so big, then perhaps you should re-think your entire interaction model with the data. Why not do something like if you select a button in your view, your UI changes to reveal a completely new view with the data you like to present in there? A cell in a table is only so big, and not really suited to interact with a lot of data at a time. In such a setup, no special delegates are needed at all.

  • Thanks for the quick response!

    I did delegate: the input box with a button. Pressing the button causes TableView with data from another table. But now I do not know how to return the data in the first table.

    My delegate:

    @class DelegatPerson : public QItemDelegate
    DelegatPerson (int id, QAbstractItemModel* model, QWidget *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;

    virtual void paint (QPainter *painter,
                const QStyleOptionViewItem& option, const QModelIndex& index ) const;

    // virtual bool editorEvent(QEvent *event,
    // QAbstractItemModel *model, const QStyleOptionViewItem &option,
    // const QModelIndex &index);
    public slots:
    void showPesonCatalog ();
    void setRelationData (const QModelIndex &index);
    void repaint () const;
    //void callRelationCatalog (QAbstractItemModel model) const;
    CCatalogPerson catPerson;
    sourceModel; //model of the owner
    QModelIndex sourceIndex;
    QWidget *myParent;
    // CEditLineButton *editor ;
    // ViewPerson *editor ;
    //void setModelParamet ( QAbstractItemModel *model, QModelIndex &index);
    Widget for editor in delegate:

    @class LineEdit : public QLineEdit

    LineEdit( QWidget *parent = 0);
    ~LineEdit ();

    void resizeEvent(QResizeEvent *);

    private slots:
    void updateCloseButton(const QString &text);
    void pressButton ( );
    void clicked ();
    QToolButton *clearButton;
    //CCatalogPerson *catPerson;
    // QModelIndex *parentIndex;

  • I also have another question:
    how can I recognize finish editing in delegate?

  • normally, when editing is finished, setModelData is called. If you want to know, when this happens, it's mostly a slot connected to the "User property" change signal of the editor widget

    aditioanlly some events (mouse click etc) can lead to this.

  • The problem isn't a lot of in other. At me the editor is the widget consisting of entry field from the button lying on it. At a click by the button there should be a coherent table. But when I press the button at once there is a call setDataModel and only another is then created TableView.

Log in to reply