Python Forum
Convert python to Qt c++
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert python to Qt c++
#2
This is the code I ended up with (from the QSqlRelationalDelegate 's code), and works!
Any comments are welcome.
    int positionColumn = 2;
    qDebug()<< "BookDelegate.createEditor index.column()=" << (index.column()) << " option=" << option ;
    if (index.column() == positionColumn){
        const QSqlRelationalTableModel *sqlModel = qobject_cast<const QSqlRelationalTableModel *>(index.model());
        QSqlTableModel *childModel = sqlModel ? sqlModel->relationModel(index.column()) : nullptr;
        if (!childModel)
            return QStyledItemDelegate::createEditor(parent, option, index);

        QComboBox *combo = new QComboBox(parent);
        combo->setModel(childModel);
        combo->setModelColumn(1);
        combo->installEventFilter(const_cast<BookDelegate *>(this));
        childModel->select();
        return combo;
    }
Reply


Messages In This Thread
Convert python to Qt c++ - by panoss - Feb-05-2022, 03:14 PM
RE: Convert python to Qt c++ - by panoss - Feb-05-2022, 06:56 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020