Results 1 to 6 of 6

Thread: Custom Widget inside a QVboxLayout

  1. #1
    Join Date
    Jun 2008
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question 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
    Can you give me a solution?

    Thanks a lot!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widget inside a QVboxLayout

    If you replace you custom widget with a button or other standard widget, can you see it?

  3. #3
    Join Date
    Jun 2008
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widget inside a QVboxLayout

    Yes, If I use standard widgets I can see all of them!

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widget inside a QVboxLayout

    Quote Originally Posted by nemesis View Post
    Yes, If I use standard widgets I can see all of them!
    Hmm... What are the values of sizePolicy and minimumSize properties?

  6. #6
    Join Date
    Jun 2008
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widget inside a QVboxLayout

    I have solved the problem!!!

    Here was the code before I fixed it:

    Qt Code:
    1. QWidget* privateLayoutWidget = new QWidget( this, "layout2" );
    2. privateLayoutWidget->setGeometry( QRect( 0, 0, 642, 400 ) );
    3. layout2 = new QVBoxLayout( privateLayoutWidget, 11, 6, "layout2");
    4.  
    5. textLabel3 = new QLabel( privateLayoutWidget, "textLabel3" );
    6. textLabel3->setMinimumSize( QSize( 640, 16 ) );
    7. textLabel3->setAlignment( int( QLabel::AlignCenter ) );
    8. layout2->addWidget( textLabel3 );
    9.  
    10. plt = new plotter();
    11. layout2->addWidget( plt);
    To copy to clipboard, switch view to plain text mode 

    I did not set the parent when I created the plotter instance.
    I corrected this code to:

    Qt Code:
    1. QWidget* privateLayoutWidget = new QWidget( this, "layout2" );
    2. privateLayoutWidget->setGeometry( QRect( 0, 0, 642, 400 ) );
    3. layout2 = new QVBoxLayout( privateLayoutWidget, 11, 6, "layout2");
    4.  
    5. textLabel3 = new QLabel( privateLayoutWidget, "textLabel3" );
    6. textLabel3->setMinimumSize( QSize( 640, 16 ) );
    7. textLabel3->setAlignment( int( QLabel::AlignCenter ) );
    8. layout2->addWidget( textLabel3 );
    9.  
    10. plt = new plotter(privateLayoutWidget);
    11. plt->setMinimumSize(640,200);
    12. layout2->addWidget( plt);
    To copy to clipboard, switch view to plain text mode 

    And now it works!
    I'm reading some texts to know why is it necessary to specify the parent widget...

    Thanks a lot!

Similar Threads

  1. Custom Widget - First Steps
    By sekatsim in forum Qt Programming
    Replies: 8
    Last Post: 26th June 2008, 17:19
  2. Replies: 5
    Last Post: 25th May 2008, 08:22
  3. Replies: 3
    Last Post: 17th March 2008, 19:54
  4. Custom widget
    By zorro68 in forum Qt Programming
    Replies: 7
    Last Post: 28th January 2008, 14:06
  5. custom plug-in widget in another custom plug-in widget.
    By MrGarbage in forum Qt Programming
    Replies: 6
    Last Post: 27th August 2007, 15:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.