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 5963835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:19:28+00:00 2026-05-22T19:19:28+00:00

I am trying to implement a widget in Qt that has 2 child widgets

  • 0

I am trying to implement a widget in Qt that has 2 child widgets of its own: one is a render area where I draw some points and connect lines between them and the other one is a ListBox where I would like to insert the list of all the points I drew with their coordinates from the render area. The 2 widgets where added with Qt Designer. Here is my code until now:

renderarea.h:


class RenderArea : public QWidget
{
    Q_OBJECT

public:
    RenderArea(QWidget *parent = 0);
    QPoint point;
    QList<QPoint> list;

protected:
    void mousePressEvent(QMouseEvent *);
    void paintEvent(QPaintEvent *event);
    void updateList(QPoint p);
};

renderarea.cpp:


RenderArea::RenderArea(QWidget *parent)
    : QWidget(parent)
{
    setBackgroundRole(QPalette::Base);
    setAutoFillBackground(true);
}

void RenderArea::mousePressEvent(QMouseEvent *e)
{
    point = e->pos();
    updateList(point);
    this->update();
}

void RenderArea::updateList(QPoint p)
{
    list.append(p);
}
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]);
}

paintwidget.h:


class PaintWidget : public QWidget
{
    Q_OBJECT

public:
    explicit PaintWidget(QWidget *parent = 0);
    ~PaintWidget();

private:
    Ui::PaintWidget *ui;
};

paintwidget.cpp:


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

PaintWidget::~PaintWidget()
{
    delete ui;
}

My question is how to transmit from the render area widget to my ListBox that I drew another point and it should be displayed along with its coordinates in the list?

  • 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-22T19:19:29+00:00Added an answer on May 22, 2026 at 7:19 pm

    OrcunC gave you a good advice.
    If your are new to signal/slots implementation here some hints you can start from.

    renderarea.h

    signal:
        void pointAdded(QPoint*);
    

    renderarea.cpp

    void RenderArea::updateList(QPoint p)
    {
        list.append(p);
        emit pointAdded(&list.back());
    }
    

    listbox.h

    public slots:
        void onPointAdded(QPoint*);
    

    listbox.cpp

    void ListBox::onPointAdded(QPoint* point)
    {
        //lets assume your ListBox is a QListWidget
        addItem( QString::number(point->x()) + "," + QString::number(point->y()))
    }
    

    somewhere instance of ListBox and RenderArea are accessible

    QObject::connect( renderArea, SIGNAL(pointAdded(QPoint*),
                      listBox,    SLOT(onPointAdded(QPoint*)));
    

    NOTE: nameing is very important for readability and maintenance the void RenderArea::updateList(QPoint p) in this case it’s more void RenderArea::addPoint( const QPoint& p) (also notice the const reference telling the compiler that we are not changing p event if we have it’s reference)

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

Sidebar

Related Questions

I'm trying to implement a iGoogle like dashboard interface using widgets that get their
I am trying to implement two different searchable activities, one for honeycomb(with search widget)
I'm trying to implement a Widget control that exists on every page in the
im trying to implement some behaviors when a mapview element scrolls... by coding a
when trying to implement an Aspect, that is responsible for catching and logging a
I am trying to have some fun with dashboard widgets, so I tried a
i'm trying to use jquery to implement a portlet/widget style interface, with 3 columns
I'm trying to implement the Star Rating Widget with 5 stars split in half,
I am trying to implement a custom Java widget using GWT.This requires me to
I am trying to implement a custom Java widget using GWT.This requires me to

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.