PDA

View Full Version : Need help with QFrame sizing on widget



kachofool
27th December 2010, 03:33
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.



SeriesViewer::SeriesViewer(QWidget *parent) :
QWidget(parent)
{
this->setFixedSize(420,420);

_imageFrame = new QFrame(this);
_imageFrame->setFrameShape(QFrame::Panel);
_imageFrame->setLineWidth(5);
repaint();

}


OR



SeriesViewer::SeriesViewer(QWidget *parent) :
QWidget(parent)
{
this->setFixedSize(420,420);

_imageFrame = new QFrame(QRect(0,0,250,250));
_imageFrame->setFrameShape(QFrame::Panel);
_imageFrame->setLineWidth(5);
repaint();

}


Output is the same:

http://img440.imageshack.us/img440/2806/screenshotvjv.png

Could anyone tell me where I'm going wrong?


Regards,

KF

AlexSudnik
27th December 2010, 07:17
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:


SeriesViewer::SeriesViewer(QWidget* parent):QWidget(parent)
{

frame=new QFrame;

QVBoxLayout* mainLayout=new QVBoxLayout; //substitute VBoxLayout with whatever you need

mainLayout->addWidget(frame);

setLayout(mainLayout);

}


Now you've got your objects' hierachy with a proper layout management.