Nominate our 2022 Qt Champions!

ModelView programing with Delegate in qt

  • When I create QSpinBox in createEditor() of QStyleItemDelegate class,It displays in side the cell of the QTableview.
    But when I create QDialog in that function,It gets display out side(seperatly).What could be the reason?

  • Lifetime Qt Champion

    A dialog is a windows type and not embeddable as a widget.
    You can just use QWidget as base class and it will work.
    Since you want to put it inside the cell, QDialog is not the right base class.

  • @mrjj yeah thanks..I will try it using QWidgets.

  • Lifetime Qt Champion

    Its just 2 place to change in code then its Qwidget.
    No reason to recreate it all again. very easy to switch.

    In .h
    class mine : public QDialog <<< the actual base

    and in .cpp
    mine::mine(QWidget *parent) : QDialog(parent), << change the call to base for constructor

    maybe #include <QWidgets> instead of QDialog

    there is also
    after you construct the dialog.
    It might do the same. not tested. though.

Log in to reply