Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to add a widget in a QTableView?



  • I'm developing a software for trading, and in the shopping cart I'm trying to add a QDoubleSpenBox in each cell of a column so I can provide a way to change the amount of items in the cart

    int row = modeloTabela->rowCount();
    
                QDoubleSpinBox *dsbQuantidade = new QDoubleSpinBox();
                dsbQuantidade->setMaximum(produto.quantidadeDouble());
    
                ui->tvCarrinho->setIndexWidget(modeloTabela->index(0, 2), dsbQuantidade);
    

    But nothing happens

    ![alt text](0_1558802014742_936ea180-5398-4874-a1d9-f220442fc422-image.png image url)


  • Lifetime Qt Champion

    Hi,

    Why set a widget ? You should take a look at the Spin Box Delegate Example. It will likely be what you are looking for.


Log in to reply