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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:20:42+00:00 2026-05-11T10:20:42+00:00

I have a simple hierarchy of widgets: GraphWidget -> MotionWidget -> NodeWidget. I am

  • 0

I have a simple hierarchy of widgets: GraphWidget -> MotionWidget -> NodeWidget. I am new to Qt, so I am not quite sure about how some insides work yet. Basically, GraphWidget creates a single MotionWidget M and sets M’s parent to itself. M then goes away and creates a bunch of NodeWidgets. However, NodeWidgets never get painted nor does their paintEvent() function gets called.

I tried creating MotionWidget directly, without GraphWidget and everything works. So why does things break if I add GraphWidget to the hierarchy?

Here is a paste with the relevant bits of code from my project. I also included the output from GraphWidget::dumpObjectTree() at the top.

Edit: forgot to include the paste link 😉 http://rafb.net/p/Zp39CF94.html

Update: I wrapped MotionWidget into a layout.

Before:

GraphWidget :: GraphWidget( QWidget *parent ) : QWidget( parent ) {     setFixedSize( 500, 500 );      MotionWidget *n = new MotionWidget( 5, this ); } 

After

GraphWidget :: GraphWidget( QWidget *parent ) : QWidget( parent ) {     setFixedSize( 500, 500 );      QVBoxLayout *l = new QVBoxLayout;      MotionWidget *n = new MotionWidget( 5 );      l->addWidget( n );      setLayout( l ); } 

Now, the latter works. I.e. everything gets drawn. The question then becomes… Why? Why didn’t it work in the first case but worked in the second?

  • 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. 2026-05-11T10:20:43+00:00Added an answer on May 11, 2026 at 10:20 am

    I’m going to disagree with Aiua’s answer. Passing the parent to an object will add the child to the visual hierarchy. (Otherwise, using Designer to make a widget including others, but with absolute positioning, wouldn’t work.) However, there were probably other factors keeping the painting from happening.

    Due to the fact that the layout made things work, I’m going to guess that in both versions, MotionWidget has no set size. That would mean in the first example that it would be sized to 0x0 pixels, which Qt will optimize out when trying to paint. In the second example, the layout controls the size of the widgets added to it, and so would enlarge MotionWidget, and thus it would start to receive paint events again.

    To fix this, you could set the size explicitly like you do for GraphWidget, or you could do some dynamic sizing based on the parent’s size, or GraphWidget could control the size, or any of a large number of various options. Layouts can be nice also, but aren’t absolutely required.

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

Sidebar

Related Questions

i have some simple hierarchy of widgets looks something like this : MainWindow->setObjectName(QString::fromUtf8(MainWindow)); MainWindow->resize(423,
I have a simple Class Hierarchy that I am trying to get to work
I'm sure this has a very simple answer I am not finding... I have
I have a pretty simple class hierarchy: public class DropdownOption<T> /* does NOT implement
I have a class manipulating only shared_ptr to an inheritance hierarchy (quite simple, there
I have a simple hierarchy of component in MySQL which is described by a
I have a simple hierarchy of categories in an SQLite3 database, each row storing
I have a simple object hierarchy, and I want to query each of the
I have this simple exception hierarchy: type FirstLevelException(msg) = inherit System.Exception (msg) type SecondLevelException(msg,
I have created a simple UIView hierarchy in IB: Parent (UIView) child (UIView) child

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.