Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6198721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:03:55+00:00 2026-05-24T04:03:55+00:00

I have this application where the user can draw some custom QGraphicsItems in a

  • 0

I have this application where the user can draw some custom QGraphicsItems in a QGraphicsView and I would like that some data about those items be also displayed in a QTableWidget.

The code for the custom QGraphicsItem:
header file:


    class Clothoid : public QGraphicsItem
    {
    public:
        Clothoid(QPoint startPoint, QPoint endPoint);
        virtual ~Clothoid();

        QPoint sPoint;
        QPoint ePoint;
        CFloat startCurvature;
        CFloat endCurvature;
        CFloat clothoidLength;
        CFloat tangentAngle;
    ...
    }

cpp file:


    Clothoid::Clothoid(QPoint startPoint, QPoint endPoint)
    {
        sPoint = startPoint;
        ePoint = endPoint;
        startCurvature = 0.0;
        endCurvature = 0.0;
        clothoidLength = sqrt(pow(endPoint.x() - startPoint.x(),2) +
                              pow(endPoint.y() - startPoint.y(),2));
    }

The code for the Graphics view:


    renderArea::renderArea(QWidget *parent):
            QGraphicsView(parent)
    {
        scene = new QGraphicsScene(this);
        scene->setItemIndexMethod(QGraphicsScene::NoIndex);
        scene->setSceneRect(0, 0, 850, 480);
        setScene(scene);
        setCacheMode(CacheBackground);
        setViewportUpdateMode(BoundingRectViewportUpdate);
        setRenderHint(QPainter::Antialiasing);
        setTransformationAnchor(AnchorUnderMouse);
        scale(qreal(1.0), qreal(1.0));
        setMinimumSize(400, 400);
    }

    void renderArea::mousePressEvent(QMouseEvent *event)
    {
        QPoint p = event->pos();

        updateList(p);
    }

    void renderArea::updateList(const QPoint &p)
    {
        Point point;
        point.point = p;
        point.isSelected = false;
        list.append(point);
        if (list.size() > 1)
            updateClothoid(list[list.size()-2].point, list[list.size()-1].point);
    }

    void renderArea::updateClothoid(const QPoint &p1, const QPoint &p2)
    {
        Clothoid *temp = new Clothoid(p1, p2);

        clothoids.append(temp);

        scene->addItem(temp);

        emit clothoidAdded(&clothoids);
    }

where clothoids are defined as:


QList clothoids;

I connect the signal with the slot in another class special for the table widget:


    void TableViewList::onClothoidAdded(QList *clothoids)
    {
        setRowCount(clothoids->size());

        for (int i = 0; i size(); i++){
            setItem(i+1, 0, new QTableWidgetItem(clothoids->at(i)->startCurvature));
            setItem(i+1, 1, new QTableWidgetItem(clothoids->at(i)->endCurvature));
            setItem(i+1, 2, new QTableWidgetItem(clothoids->at(i)->clothoidLength));
            setItem(i+1, 3, new QTableWidgetItem(clothoids->at(i)->sPoint.x() + ", " +
                                               clothoids->at(i)->sPoint.y()));
            setItem(i+1, 4, new QTableWidgetItem(clothoids->at(i)->ePoint.x() + ", " +
                                               clothoids->at(i)->ePoint.y()));
        }

    }

The problem is that the data isn’t inserted in the table. I checked with debugging and I saw that the array holds the wanted data. How could I access it correctly? Any ideas?

When trying with QTableView and QStandardItemModel I encounter this problem: the data in the model is not inserted in the table:


    renderingWidget::renderingWidget(QWidget *parent) :
            QWidget(parent),
            ui(new Ui::renderingWidget)
    {
        ui->setupUi(this);

        model.setColumnCount(3);
        ui->clothoidTable->setModel(&model);

        SpinBoxDelegate delegate;
        ui->clothoidTable->setItemDelegate(&delegate);


        connect (ui->saveButton, SIGNAL(clicked()), this, SLOT(createClothoid()));
    }


    void renderingWidget::createClothoid()
    {
        model.setRowCount(model.rowCount()+1);

        QModelIndex index = model.index(model.rowCount(), 1, QModelIndex());
        model.setData(index, QVariant(ui->lengthSpinBox->value()));
        index = model.index(model.rowCount(), 2, QModelIndex());
        model.setData(index, QVariant(ui->sCurvSpinBox->value()));
        index = model.index(model.rowCount(), 3, QModelIndex());
        model.setData(index, QVariant(ui->eCurvSpinBox->value()));

        ui->clothoidTable->setModel(&model);
    }

I want to be able to insert the data in some text boxes/spin boxes and then on button click the data should be added in the table. But only the number of rows is updated not the data within. Am I doing anything wrong while setting the data for the model?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:03:56+00:00Added an answer on May 24, 2026 at 4:03 am

    This is going to be hard to hear, but I’d back away from the QTableWidget convenience class.

    Check this link on Qt Model/View Programming out for how Qt is really meant to handle complex tables like yours.

    My two cents on Model/Views is this:

    1. Use a QTableView instead of a QTableWidget.
    2. Subclass QAbstractItemModel and implement data() (for reading), and
      all the other functions you need from the documentation. This is the
      trickiest part, but refer to the above link for a walkthrough of how
      to do this.
    3. setModel() of the QTableView to your subclassed model.

    If you have more questions, I’ll be happy to answer them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this little application, and what it does is a user can add
I am creating this drawing application, where the user can click preview and it
In our application user can create different lists (like sharepoint) for example a user
I have this code in a C application that's embedding Python (2.7.1): { PyObject
In my application I have a map, this map has a lot of annotations...
I have a console application from which I create a window. I can render
I am developing an application in which user can purchase any image he likes.
I have this alert view (disclaimer) that pop up when app finish launching. It
I need to have a textbox (sort of) where the user can enter text
I am struggling with a weird problem. I have an application manifest that defines

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.