PDA

View Full Version : Resize a Widget



sonu
27th October 2007, 08:54
Hello Everyone ,
I want to display a .jpg file in a child widget through QHboxLayOut class in a parent widget.
but it is not helping me. I mean it does not resize according to given Geometry......
My code is as follows........
QLabel *imageLabel;
imageLabel = new QLabel;
imageLabel->setBackgroundRole(QPalette::Base);
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);

imageLabel->setScaledContents(true);
QImage image(mediaPath[currentIndex]);
imageLabel->setPixmap(QPixmap::fromImage(image));
QHBoxLayout *layout = new QHBoxLayout(parentWidget);
layout->addWidget(imageLabel);
parentWidget->setLayout(layout);
If anyone has any idea about it please give reply
Thanks.:(

jpn
27th October 2007, 12:47
Is the parentWidget a window or in a layout?

sonu
27th October 2007, 13:52
No Sir , the parent Widget is not a window .
It is also widget and a child of another QHboxlayOut Object.

jpn
27th October 2007, 14:23
No Sir , the parent Widget is not a window .
It is also widget and a child of another QHboxlayOut Object.
And is this layout installed on a widget? You must have a hierarchy of layouts up to the top level widget, aka window.

momesana
27th October 2007, 20:38
It would be helpful if you post a minimal compilable piece of code, highlighting the problem, as far as it is possible to rip that part out of the program and still reproduce the same result. Otherwise give us at least the class where the above code is defined.

sonu
28th October 2007, 07:07
Sir i can't understand your reply .please explain it clearly.:confused:

momesana
28th October 2007, 08:05
It's hard to draw conclusions without seeing more code.
I am still having difficulty to understand what exactly is not working for you.

Try out this code. Does that work for you?


#include <QApplication>
#include <QtGui>

int main(int argc, char* argv[])
{
QApplication app(argc, argv);

// Image Label
QLabel* imageLabel = new QLabel;
imageLabel->setBackgroundRole(QPalette::Base);
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
imageLabel->setScaledContents(true);

// Loading Image
QString fileName = QFileDialog::getOpenFileName(0,
QObject::tr("Open image"),
QApplication::applicationDirPath(),
QObject::tr("Images (*.jpg *.png *.gif *.xpm)"));
imageLabel->setPixmap(fileName);

// CentralWidget
QWidget* cw = new QWidget;

// Layout
QHBoxLayout* lo = new QHBoxLayout;
lo->addWidget(imageLabel);
cw->setLayout(lo);

// Instantiating and showing mainwindow
QMainWindow mw;
mw.setCentralWidget(cw);
mw.show();
return app.exec();
}

sonu
28th October 2007, 09:04
Thanks Sir , But my problem is that i can't resize layout widget .
I mean that i m using hierarchy of layouts . and in the child widget of Parent layout also contain another layout And I want to resize this layout .:rolleyes:
If you can do something ,give reply
thanks for your suggestion ..........

jpn
28th October 2007, 09:29
Could you clearly state what you want? Keep in mind that we don't know anything about your project.

Thanks Sir , But my problem is that i can't resize layout widget .
I mean that i m using hierarchy of layouts . and in the child widget of Parent layout also contain another layout And I want to resize this layout
Well, actually you don't resize by hand anything that is managed by a layout manager. It is layout managers responsibility to maintain geometries of widgets added to it. There are a few ways (size policies, stretch factors..) to fine tune how this is done. Recommended reading: Layout Classes (http://doc.trolltech.com/latest/layout.html).

sonu
29th October 2007, 08:06
Could you clearly state what you want? Keep in mind that we don't know anything about your project.

Well, actually you don't resize by hand anything that is managed by a layout manager. It is layout managers responsibility to maintain geometries of widgets added to it. There are a few ways (size policies, stretch factors..) to fine tune how this is done. Recommended reading: Layout Classes (http://doc.trolltech.com/latest/layout.html).

Sir, I m trying this but it is not helpful.
Sir in actual i have a parent widget which contain a HBoxLayout with three child widget. Now I m adjust another QHBoxLayout in one of this child widget. But it does not resize acc. to given Geometry.
So please if u have any idea about it give reply....
thanks.........