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

The Archive Base Latest Questions

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

I create class Widget, it creates window, this class paints something on the window

  • 0
  1. I create class Widget, it creates window, this class paints something on the window (i.e. it works as I want).
  2. I create yet one class, Circle, I want to paint on the window of class Widget.
  3. I pass adress of Widget and try to paint on Widget using QPainter paint (address of Widget); (in the instance of Circle) but i don’t see anything.

I’ve tried to make code as shorter as possible during the execution of program I type out address of object Widget. It doesn’t change. It means that the address of Widget was passed right.

Everywhere, where I type out address of Widget I receive the same address. Here is the code:

header Widget

            class Widget : public QWidget
            {
                public:
                int  mi,mcount;
                Widget(QWidget *parent = 0);
                QPaintEvent *ev;
                virtual void paintEvent(QPaintEvent *);
            void drawcircle();
            };

Widget.cpp

Widget::Widget(QWidget *parent) : QWidget(parent)
{
    QWidget::paintEvent(ev);

    qDebug()<<this<<"\n";  //
}

        void Widget::drawcircle()
        {
        QPainter paint(this);
        paint.drawEllipse(0,0,100,100);
        }


void Widget::paintEvent(QPaintEvent *ev)
{    this->drawcircle(); }

header Circle.h

        class Circle :public QWidget
        {
            public:
            Circle(Widget *widget);    // i do trick here!!!
            Widget *mwidg;
        QPaintEvent *ev;

        virtual void paintEvent(QPaintEvent *);
        void drawcircle(Widget *mwidg);
        };

Circle.cpp

    Circle::Circle(Widget *widget)
        {
        qDebug()<<"circle widget"<<widget;
        QWidget::paintEvent(ev);
        mwidg=widget;
        qDebug()<<"\n"<<mwidg;
        }



    void Circle::paintEvent(QPaintEvent *ev)
    {  qDebug()<<"circle paintEvent mwidget"<<mwidg<<"\n";
    this->drawcircle(mwidg);
        }


        void Circle::drawcircle(Widget *mwidg)
            {
                QPainter paint(mwidg);
                paint.drawEllipse(20,10,40,40);
            paint.drawLine(0,0,500,500);
            }

main

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        Widget *w=new Widget;

            qDebug()<<"main address of widget"<<w<<"\n";
        Circle *f=new Circle(w);
        w->show();

        return a.exec();
        }

program is compiled and linked successful

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

    well , thank you for your attempts to help
    but all that i was needing:

    this -> setParent(widget);

    in costructor Circle::Circle, if somebody’ll want to see my solve,one can see that figures are moved

    source code is here source code

    enter image description here

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

Sidebar

Related Questions

I've found a task on some Java programming competition. One must create class Sentence
I amk new to qt. I tried to create a window with a widget.
Qt creator has option to promote one widget to customly created class that derives
I am writing a GTKmm window program; the main window creates two buttons, one
I create class libraries, some which are used by others around the world, and
How do I create class (i.e. static ) variables or methods in Python?
I need to create class Dog and PurebredDog extending Dog. Problem is that Dog
I have been curious about dynamically create class at runtime in C# and stumbled
I wonder, whether it is possible to create class-methods in VBA. By class-method I
If I create a class like so: // B.h #ifndef _B_H_ #define _B_H_ class

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.