Important: Please read the Qt Code of Conduct -

How to add coustem widget to QTableView Model

  • I having a QTableView in my project i use QStandardItemModel to make the table and set this model to the QTableView
    i use this code to make the table

    QStandardItemModel *model = new QStandardItemModel();

    then I start to add items using QStandardItem, I have a column which is called statue which I want to add in it a spinner progress bar to all the rows in this columns
    so I use this code to add it also i use it after set the model

        SpinnerProgressBar bar = new SpinnerProgressBar();
        ui->tableView->setIndexWidget(ui->tableView->model()->index(i, 3), bar );

    i use it in a loop so i can loop on all the table and add the progress bar to each row the problem here is when I use this code it add the spinner progress bar widget in front of the table not in each cell if I use the QPushButton for example or any Qt widget it works fine so what makes this problem happened what mistake I make here
    i got the spinner widget from an open source project here
    Thanks in advance

  • Lifetime Qt Champion

    its because its a dialog.

    WaitingSpinnerWidget::WaitingSpinnerWidget(Qt::WindowModality modality,
                                               QWidget *parent,
                                               bool centerOnParent,
                                               bool disableParentWhenSpinning)
        : QWidget(parent, Qt::Dialog | Qt::FramelessWindowHint),

    You can try
    SpinnerProgressBar bar = new SpinnerProgressBar();
    ui->tableView->setIndexWidget(ui->tableView->model()->index(i, 3), bar );

  • @mrjj it still showed in the middle of the table view, not in the cell

  • Lifetime Qt Champion

    Ok, it seems to have

     WaitingSpinnerWidget(QWidget *parent = 0,
                             bool centerOnParent = true,
                             bool disableParentWhenSpinning = true);

    try create it with FALSE for centerOnParent
    as in
    pinnerProgressBar bar = new SpinnerProgressBar(0, FALSE);

Log in to reply