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. Special delegate for QTableView
QtWS25 Last Chance

Special delegate for QTableView

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 4.0k Views
  • 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.
  • K Offline
    K Offline
    kunashir
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

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

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kunashir
          wrote on last edited by
          #4

          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
          {
          Q_OBJECT
          public:
          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);
          signals:
          void repaint () const;
          //void callRelationCatalog (QAbstractItemModel model) const;
          private:
          CCatalogPerson catPerson;
          QAbstractItemModel
          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
          {
          Q_OBJECT

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

          protected:
          void resizeEvent(QResizeEvent *);

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

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kunashir
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #6

              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.

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kunashir
                wrote on last edited by
                #7

                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.

                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