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. How to set QScrollArea centralWidget ?
Forum Updated to NodeBB v4.3 + New Features

How to set QScrollArea centralWidget ?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 1.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.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1

    I need QScrollArea.size fit MainWindow.size when resize.

    MainWindow
    {
        resize(600,400);
        QWidget *widget = new QWidget;    
        widget->setMinimumSize(1000,260);
        setCentralWidget(widget);
        QScrollArea *scrollArea = new QScrollArea(this);
        scrollArea->setWidget(widget);
        scrollArea->setFixedSize(500,260);
    }
    

    替代文字

    https://github.com/sonichy

    jsulmJ 1 Reply Last reply
    0
    • sonichyS sonichy

      I need QScrollArea.size fit MainWindow.size when resize.

      MainWindow
      {
          resize(600,400);
          QWidget *widget = new QWidget;    
          widget->setMinimumSize(1000,260);
          setCentralWidget(widget);
          QScrollArea *scrollArea = new QScrollArea(this);
          scrollArea->setWidget(widget);
          scrollArea->setFixedSize(500,260);
      }
      

      替代文字

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @sonichy said in How to set QScrollArea centralWidget ?:

      scrollArea->setFixedSize(500,260);

      Then why do you set fixed size?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      sonichyS 1 Reply Last reply
      0
      • jsulmJ jsulm

        @sonichy said in How to set QScrollArea centralWidget ?:

        scrollArea->setFixedSize(500,260);

        Then why do you set fixed size?

        sonichyS Offline
        sonichyS Offline
        sonichy
        wrote on last edited by
        #3

        @jsulm If scrollArea do not setFixedSize, the scrollArea collapse.
        替代文字

        https://github.com/sonichy

        jsulmJ 1 Reply Last reply
        0
        • sonichyS sonichy

          @jsulm If scrollArea do not setFixedSize, the scrollArea collapse.
          替代文字

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @sonichy Because you did not put your scroll area in a layout...

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            What don't you set the QScrollArea as central widget of your QMainWindow ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            JonBJ 1 Reply Last reply
            1
            • SGaistS SGaist

              Hi,

              What don't you set the QScrollArea as central widget of your QMainWindow ?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @SGaist
              I'm interested: is the code as stands "allowed"? QMainWindow has its centralWidget set to a widget, and then the QScollArea sets as its widget the QMainWindow::centralWidget. So presently the scroll area has been placed "outside" the main window's central widget. We have separate QMainWindow->QWidget and QScrollArea->QWidget. Are you allowed to create a QScrollArea and then just "put it on" some existing widget in the hierarchy (without actually inserting it into the hierarchy so that it becomes QMainWindow->QScrollArea->QWidget)?

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                You can have floating widgets. The thing that is wrong here is that "widget" is set as the QMainWindow and as the QScrollArea "central widget". From the description it should just be:

                • Create widget
                • Create QScrollArea
                • Set widget in QScrollArea
                • Set scroll area as QMainWindow central widget

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                JonBJ sonichyS 2 Replies Last reply
                3
                • SGaistS SGaist

                  You can have floating widgets. The thing that is wrong here is that "widget" is set as the QMainWindow and as the QScrollArea "central widget". From the description it should just be:

                  • Create widget
                  • Create QScrollArea
                  • Set widget in QScrollArea
                  • Set scroll area as QMainWindow central widget
                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @SGaist
                  Absolutely, that is what @sonichy should do. That is hierarchy QMainWindow->QScrollArea->QWidget.

                  But from what he originally wrote and what you say. if I have an existing hierarchy of widgets, if I feel like it I am allowed to just go QScrollArea::setWidget() to some widget already there, without actually inserting my QScrollArea, and that is allowed? I can add scrolling to any widget that way and it works?

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Some widget already inherit from QScrollArea, so no need for them but otherwise that's the idea yes.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    1
                    • SGaistS SGaist

                      You can have floating widgets. The thing that is wrong here is that "widget" is set as the QMainWindow and as the QScrollArea "central widget". From the description it should just be:

                      • Create widget
                      • Create QScrollArea
                      • Set widget in QScrollArea
                      • Set scroll area as QMainWindow central widget
                      sonichyS Offline
                      sonichyS Offline
                      sonichy
                      wrote on last edited by
                      #10

                      @SGaist Solved!

                      setCentralWidget(scrollArea);
                      

                      https://github.com/sonichy

                      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