[Moved] I can’s limited the size of custum widget inherited Qwidget in mainwindow



  • I can's limited the size of custum widget inherited Qwidget in mainwindow

    sizehint() is implemented , resize() & setgeometry() is not usefull !

    and ?





  • @
    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();
    @



  • It's not usefully



  • along with Fixed size policy, try to also set the minimum and maximum sizes for the widget, it should work



  • 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 !


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.