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. Dynamically change delegate QTableView
Forum Updated to NodeBB v4.3 + New Features

Dynamically change delegate QTableView

Scheduled Pinned Locked Moved Solved General and Desktop
26 Posts 3 Posters 8.1k Views 2 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.
  • SGaistS SGaist

    Hi,

    Can you show how you are using it ?

    E Offline
    E Offline
    EagleWatch
    wrote on last edited by
    #21

    @SGaist
    Hi,

    Thank you for asking.
    When searching to answer you, I realized that I forgot to remove some tests with the m_delegate pointer.
    That's why I had the error.

    Now I have all necessary informations, I'll try to customize this subclass to fit with what I want.

    I'll keep you updated guys.

    Thanks.

    1 Reply Last reply
    0
    • E Offline
      E Offline
      EagleWatch
      wrote on last edited by
      #22

      Hi guys,

      I've some news.

      So after some days studying classes I was using, I discoverd that my problem was not because of the QSqlRelationalDelegate class.
      In fact, that was the QSqlRelationalTableModel.

      When I create the QSqlRelationalTableModel, I had to set a relation.
      When doing this, the QSqlRelationalTableModel keeps in cache the model given by the relation.

      Even if we change the relation, the model is still the same, that why the combobox was always showing the same data.

      For now, I just delete the QSqlRelationalTableModel and recreate it with the new relation and it works like a charm.

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #23

        Do you mean that if you call setRelation a second time it won't work ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • E Offline
          E Offline
          EagleWatch
          wrote on last edited by
          #24

          Absolutely.

          All tests I've done have confirmed that.
          The model doesn't change at all.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #25

            Can you provide a minimal compilable example that shows that ?

            You should also check the bug report system to see if it's something known.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • E Offline
              E Offline
              EagleWatch
              wrote on last edited by
              #26

              Considering we have 3 table :

              Integrity{
              id INTEGER PRIMARY KEY AUTOINCREMENT,
              level VARCHAR(100),
              definition VARCHAR(500)
              }
              Confidentiality{
              id INTEGER PRIMARY KEY AUTOINCREMENT,
              level VARCHAR(100),
              definition VARCHAR(500)
              }
              Proba{
              id INTEGER PRIMARY KEY AUTOINCREMENT,
              id_crit INT,
              somethingelse VARCHAR(500);
              }

              mainWindow.h

              private :
                  QSqlRelationalTableModel *m_tableModel;
              
              private slots:
                  void slot_refreshRelation();
              

              mainWindow.cpp

              m_tableModel = new QSqlRelationalTableModel();
              m_tableModel->setTable("Proba");
              m_tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
              m_tableModel->setRelation(1, QSqlRelation("Integrity", "id", "level"));
              m_tableModel->select();
              
              ui->tableView->setModel(m_tableModel);
              ui->tableView->hideColumn(0);
              ui->tableView->setItemDelegate(new QSqlRelationalDelegate(ui->tableView);
              
              qDebug() << m_tableModel->relationModel(1)->tableName; // Will show : Integrity
              
              connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(slot_refreshRelation()));
              
              void mainWindow::slot_refreshRelation()
              {
                  m_table->setRelation(1, QSqlRelation("Confidentiality", "id", "level"));
                  m_table->select();
                  qDebug() << m_tableModel->relationModel(1)->tableName; // Will show : Integrity
              }
              
              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