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

  • Home
  • SEARCH
  • 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 5976983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:18:20+00:00 2026-05-22T21:18:20+00:00

I am trying to implement in Qt a main window which has 2 widgets:

  • 0

I am trying to implement in Qt a main window which has 2 widgets: one area where I draw some points and one list box where I write all the points with their respective coordinates. And I would like to implement the function “delete point” of a button on the main window, i.e. when I press the button then the point selected from the list box should disappear from my area where I am drawing. So I was thinking of doing this with signals/slots, but when I try to gain access to my list of points from my drawing area it just doesn’t find any containing data. This is my code until now:

paintwidget.cpp (my main window):


PaintWidget::PaintWidget(QWidget parent) :
        QWidget(parent),
        ui(new Ui::PaintWidget)
{
    area = new RenderArea(this);
    ui->setupUi(this);
    connect(ui->displayWidget, SIGNAL(listUpdated(QList)), ui->pointsListWidget,
            SLOT(onListUpdated(QList*)));
    connect(ui->deletePoints, SIGNAL(clicked()), this, SLOT(deleteItem()));
}
void PaintWidget::deleteItem()
{
    area->deletePoint(ui->pointsListWidget->currentItem());
}

renderarea.cpp (my drawing area):


void RenderArea::mousePressEvent(QMouseEvent *e)
{
    point = e->pos();
    updateList(point);
    this->update();
}
void RenderArea::updateList(const QPoint& p)
{
    list.append(p);
    if (list.count()>1)
        lineAdded(p);
    emit listUpdated(&list);
}
void RenderArea::paintEvent(QPaintEvent * /* event */)
{
    QPainter painter(this);
    painter.setPen(QPen(Qt::black,2));
    for (int i = 0; i < list.size(); ++i)
        painter.drawPoint(list[i]);
    if (list.size()>1)
        for(int j = 0; j < list.size()-1; ++j)
            painter.drawLine(list[j], list[j+1]);
}
void RenderArea::deletePoint(QListWidgetItem *item)
{
    bool ok1;
    bool ok2;
    int index = item->text().indexOf(",");
    int x = item->text().left(index).toInt(&ok1, 10);
    int y = item->text().mid(index + 1).toInt(&ok2, 10);
    for (int i = 0; i < list.size(); ++i)
        //find the point with x and y as coordinates and delete it
}

listbox.cpp:


void ListBox::onListUpdated(QList *list)
{
    clear();
    for (int i = 0; i < list->size(); ++i)
        addItem(new QListWidgetItem(QString::number(list->at(i).x()) + ", " +
                                    QString::number(list->at(i).y())));
}

The list from the render area is a QList of QPoints. The problem is that in the FOR-loop the size of the list is 0 so I cannot see any of the points that it should contain. I think that I am failing to initialize it somewhere but I am not sure where.

The points are drawn with QPainter so when I delete the point from the list is there any possibility to delete them from my drawing area also?

  • 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-22T21:18:21+00:00Added an answer on May 22, 2026 at 9:18 pm

    I’m suspecting you’ve got two RenderArea widgets hanging around for some reason.

    You’re connecting ui->displayWidget‘s signal, but acting on the area widget for the delete.

    Shouldn’t you be calling ui->displayWidget->deletePoint or connecting area‘s signal?

    As for the repaint, you should call the widget’s update() method to have it repaint itself.

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

Sidebar

Related Questions

I am trying to implement a simple singly linked list of integers which are
trying to implement a dialog-box style behaviour using a separate div section with all
im trying to implement some behaviors when a mapview element scrolls... by coding a
I'm trying to implement some integration between a legacy app running in the Reflection
I'm trying to implement Menu in a Window using MVVM pattern. So I have
I am trying to implement a delegate method for my Cocoa document-based application which
First, some background: I am trying to implement a master-detail interface in Cocoa (for
I'm trying to implement a login window, in WPF. I have a MainWindow.xaml: <Window
I am trying to implement this MVVM pattern for the WPF form closing which
All I am currently trying implement something along the lines of dim l_stuff as

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.