Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Moved] I can’s limited the size of custum widget inherited Qwidget in mainwindow
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 4.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qzier
    wrote on last edited by
    #1

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

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

    and ?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mario
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qzier
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          Qzier
          wrote on last edited by
          #4

          It's not usefully

          1 Reply Last reply
          0
          • ? This user is from outside of this forum
            ? This user is from outside of this forum
            Guest
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mario
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • Q Offline
                Q Offline
                Qzier
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved