Results 1 to 2 of 2

Thread: Need help with QFrame sizing on widget

  1. #1
    Join Date
    Oct 2009
    Posts
    33
    Thanks
    2

    Default Need help with QFrame sizing on widget

    Hi!

    I'm unable to get QFrame to take on a particular size, or even default to the size of its parent widget. Instead, QFrame becomes a tiny rectangle, and I don't know how the size of the frame is decided. I've tried creating QFrame without specifying dimensions (in which case I thought that QFrame would take on the dimensions of the parent widget), and also by explicitly specifying a QRect. Both result in the same thing; a tiny QFrame in the widget.

    Qt Code:
    1. SeriesViewer::SeriesViewer(QWidget *parent) :
    2. QWidget(parent)
    3. {
    4. this->setFixedSize(420,420);
    5.  
    6. _imageFrame = new QFrame(this);
    7. _imageFrame->setFrameShape(QFrame::Panel);
    8. _imageFrame->setLineWidth(5);
    9. repaint();
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    OR

    Qt Code:
    1. SeriesViewer::SeriesViewer(QWidget *parent) :
    2. QWidget(parent)
    3. {
    4. this->setFixedSize(420,420);
    5.  
    6. _imageFrame = new QFrame(QRect(0,0,250,250));
    7. _imageFrame->setFrameShape(QFrame::Panel);
    8. _imageFrame->setLineWidth(5);
    9. repaint();
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    Output is the same:



    Could anyone tell me where I'm going wrong?


    Regards,

    KF

  2. #2
    Join Date
    Dec 2010
    Location
    Russia
    Posts
    83
    Thanks
    1
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Need help with QFrame sizing on widget

    Hey,

    Well,in short,making one QObject as a parent of another is goin' to activate features described in the "Object Trees and Object Ownership" section in QAssistant.So initially,it has nothig to do with layout management.So in order to perform some of those operations you can either do this manually (having QResizeEvent method reimplemented in your "CustomFrame" object, not a good idea i guess) or create a layout and place the frame into this layout.So,the code might look like this:
    Qt Code:
    1. SeriesViewer::SeriesViewer(QWidget* parent):QWidget(parent)
    2. {
    3.  
    4. frame=new QFrame;
    5.  
    6. QVBoxLayout* mainLayout=new QVBoxLayout; //substitute VBoxLayout with whatever you need
    7.  
    8. mainLayout->addWidget(frame);
    9.  
    10. setLayout(mainLayout);
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    Now you've got your objects' hierachy with a proper layout management.
    Last edited by AlexSudnik; 27th December 2010 at 10:49.

  3. The following user says thank you to AlexSudnik for this useful post:

    kachofool (28th December 2010)

Similar Threads

  1. QScrollArea Sizing
    By LIRiot in forum Newbie
    Replies: 10
    Last Post: 27th October 2010, 13:37
  2. Custom Scroll Widget Sizing Problem
    By sepehr in forum Qt Programming
    Replies: 2
    Last Post: 28th November 2008, 11:42
  3. Inherit size from ancestor Widget/QFrame
    By SenSej in forum Newbie
    Replies: 4
    Last Post: 26th September 2008, 11:55
  4. sizing question
    By jlgerber in forum Newbie
    Replies: 1
    Last Post: 20th November 2006, 16:48
  5. Sizing Issues
    By Solarity in forum Newbie
    Replies: 7
    Last Post: 13th February 2006, 19:17

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.