[Moved] I can’s limited the size of custum widget inherited Qwidget in mainwindow
-
Try changing the sizePolicy property too ("http://doc.qt.nokia.com/4.6/qwidget.html#sizePolicy-prop":http://doc.qt.nokia.com/4.6/qwidget.html#sizePolicy-prop).
See the docs for QSizePolicy: "http://doc.qt.nokia.com/4.6/qsizepolicy.html":http://doc.qt.nokia.com/4.6/qsizepolicy.html and "http://doc.qt.nokia.com/4.6/qsizepolicy.html#Policy-enum":http://doc.qt.nokia.com/4.6/qsizepolicy.html#Policy-enum
In your case I think you want to go with Fixed
-
@
ImgWdg::ImgWdg(QWidget *parent): QWidget(parent)
{
setAttribute(Qt::WA_DeleteOnClose);
// setAttribute(Qt::WA_StaticContents);
setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
pImg = NULL;
createScrolls();
}
@
@
ImgWdg * child = new ImgWdg(fileName,mdiArea);
mdiArea->addSubWindow(child);
mdiArea->cascadeSubWindows();
@ -
Ok, I haven't used MDI myself but when you create a subwindow with your widget, the widget will always be as large as the window, I think.
You have to create a container widget, add a layout to that container widget and then add your ImgWdg to the layout. Use the container widget as sub window.
Something like this:
@
ImgWdg *imgwdg = new ImgWdg(fileName);
imgwdg->setFixedSize(width, height); // Simple call this for a fixed size widget
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(imgwdg);QWidget *container = new QWidget;
container->setLayout(layout);
mdiArea->addSubWindow(container);
@As the example illustrates, you can simple call imgwdg->setFixedSize(width, height) after creating the instance to set the preferred size of the widget and it will not be resized when the window resizes.
-
@
ImgWdg::ImgWdg(QWidget *parent): QWidget(parent)
{
setAttribute(Qt::WA_DeleteOnClose);
// setAttribute(Qt::WA_StaticContents);
setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed));
// setSizePolicy(QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum));
// setSizePolicy(QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
pImg = NULL;
createScrolls();
}--
@
@
ImgWdg * child = new ImgWdg(fileName);
child->setFixedSize(600,600);
// ImgWdg * child = new ImgWdg(fileName,mdiArea);
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->addWidget(child);
QWidget * container = new QWidget;
container->setLayout(hLayout);mdiArea->addSubWindow(container); mdiArea->cascadeSubWindows(); if(child->isData){
// child->show();
container->show();
@fixed mini only , but stretch freely !