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

Add a movable tableview to a qt scene



  • Hello,
    I have a graphics scene and i want to add a tableview to the scene such that the tableview is draggable and movable within the scene rect. Can someone help me how i can achieve this ?
    Thanks for any help in advance .
    Note: I did try adding a table view widget to the scene and setting the QGraphicsItem::ItemIsMovable flag on the proxy. No luck till now.
    Here is a sample code snippet that i have tried:

        notesPageModel=new QStandardItemModel();
        notesPageModel->setItem(0,0,new QStandardItem("REFERENCE NAME"));
        notesPageModel->setItem(0,1,new QStandardItem("VALUE"));
        notesPageModel->setItem(0,2,new QStandardItem("UNIT"));
        notesPageModel->setItem(0,3,new QStandardItem("REMARKS"));
    
        notesPageTableView=new QTableView();
        notesPageTableView->setModel(notesPageModel);
        notesPageTableView->horizontalHeader()->setVisible(false);
        notesPageTableView->verticalHeader()->setVisible(false);
        notesPageTableView->setStyleSheet("QTableView::item{border : 2px solid black}");
        notesPageTableView->resizeColumnsToContents();
        QGraphicsProxyWidget *proxy1 = scene->addWidget(notesPageTableView);
        proxy1->setZValue(2);
        proxy1->setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
        notesPageTableView->setGeometry(0,0,900,600);```

  • Lifetime Qt Champion

    Hi,

    Please these a look at this stack overflow answer.

    The idea there goes in a good direction.



  • Thanks for the reply @SGaist . This helps