Custom Widget inside a QVboxLayout
I have a strange behaviour here.
I have made a custom widget (qt3). It uses double buffer: a timer event fills a pixmap and then calls repaint(). Then a paintEvent copies the pixmap into the visible area.
The widget works if used standalone without problems.
I'm trying to make a bettere interface using a QVBoxLayout.
I have used q3-designer and I vave made a simple form with a QVBoxLayout and two widgets inside.
Then I modified the code adding manually the code for my widget.. I created an instance and added in the middle.
The problem is that I cannot see this widget. I can see both the labels up and down (they are much big... like they have stretched to fill all the space).
Nothing in the middle.
I have added some debug messages inside the timer event and it is correctly called. I have added the same messages on the paintEvent and I discovered that it is never called!!
It's like the two labels fill all the space and nothing needs to be painted for my widget.
More... I have given an implementation to sizeHint e minimumSizeHint in order to return a 640,400 Qsize.
I have lost a day with this problem :crying:
Can you give me a solution?
Thanks a lot!
Re: Custom Widget inside a QVboxLayout
If you replace you custom widget with a button or other standard widget, can you see it?
Re: Custom Widget inside a QVboxLayout
Yes, If I use standard widgets I can see all of them!
Re: Custom Widget inside a QVboxLayout
DId u add the widget to the layout ??
May be thats why its not showing and not receving paint events :)
Re: Custom Widget inside a QVboxLayout
Quote:
Originally Posted by
nemesis
Yes, If I use standard widgets I can see all of them!
Hmm... What are the values of sizePolicy and minimumSize properties?
Re: Custom Widget inside a QVboxLayout
I have solved the problem!!!
Here was the code before I fixed it:
Code:
privateLayoutWidget
->setGeometry
( QRect( 0,
0,
642,
400 ) );
layout2
= new QVBoxLayout( privateLayoutWidget,
11,
6,
"layout2");
textLabel3
= new QLabel( privateLayoutWidget,
"textLabel3" );
textLabel3
->setMinimumSize
( QSize( 640,
16 ) );
textLabel3
->setAlignment
( int( QLabel::AlignCenter ) );
layout2->addWidget( textLabel3 );
plt = new plotter();
layout2->addWidget( plt);
I did not set the parent when I created the plotter instance.
I corrected this code to:
Code:
privateLayoutWidget
->setGeometry
( QRect( 0,
0,
642,
400 ) );
layout2
= new QVBoxLayout( privateLayoutWidget,
11,
6,
"layout2");
textLabel3
= new QLabel( privateLayoutWidget,
"textLabel3" );
textLabel3
->setMinimumSize
( QSize( 640,
16 ) );
textLabel3
->setAlignment
( int( QLabel::AlignCenter ) );
layout2->addWidget( textLabel3 );
plt = new plotter(privateLayoutWidget);
plt->setMinimumSize(640,200);
layout2->addWidget( plt);
And now it works!
I'm reading some texts to know why is it necessary to specify the parent widget...
Thanks a lot!