PDA

View Full Version : Custom Widget inside a QVboxLayout



nemesis
19th June 2008, 17:46
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!

jacek
22nd June 2008, 23:45
If you replace you custom widget with a button or other standard widget, can you see it?

nemesis
24th June 2008, 06:13
Yes, If I use standard widgets I can see all of them!

aamer4yu
24th June 2008, 07:54
DId u add the widget to the layout ??
May be thats why its not showing and not receving paint events :)

jacek
24th June 2008, 23:09
Yes, If I use standard widgets I can see all of them!
Hmm... What are the values of sizePolicy and minimumSize properties?

nemesis
25th June 2008, 14:55
I have solved the problem!!!

Here was the code before I fixed it:



QWidget* privateLayoutWidget = new QWidget( this, "layout2" );
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:



QWidget* privateLayoutWidget = new QWidget( this, "layout2" );
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!