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. [solved] QScrollArea on Tab with QGridLayout not working
Forum Updated to NodeBB v4.3 + New Features

[solved] QScrollArea on Tab with QGridLayout not working

Scheduled Pinned Locked Moved General and Desktop
14 Posts 2 Posters 4.6k 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.
  • R Offline
    R Offline
    RRRitchey
    wrote on last edited by
    #1

    I have read all the posts about QScrollArea I could find but so far nothing works. I have subclassed QTabWidget for my main view area:

    @SF_UnitView::SF_UnitView(QTabWidget* pParent)
    : QTabWidget(pParent)
    {
    pSystemTab = new SystemView;
    addTab(pSystemTab, tr("System"));
    }

    SF_UnitView::~SF_UnitView()
    {
    }

    void SF_UnitView::setModel(SF_UnitModel* pModel)
    {
    pSF_Model = pModel;
    pSystemTab->SetModel(pModel);
    pChannelTab = new ChannelView;
    pChannelTab->SetModel(pModel);
    insertTab(1, pChannelTab, tr("Channels"));
    }
    @

    Each tab is defined as a class. I want to add a scroll area in one of the tabs. Tabs are added after the data is read in. In this case I want to have a scroll area in the Channel tab. So far the best I get is a very small version of my window in the upper left corner of the Channel tab. The Channel tab class looks like this:

    @ChannelView::ChannelView(QWidget pParent)
    : QWidget(pParent)
    {
    pScrollArea = new QScrollArea(this);
    pScrollArea->setWidgetResizable(true);
    pGridLayoutMain = new QGridLayout(pScrollArea);
    QHBoxLayout
    pHBoxChannelLabels = new QHBoxLayout;
    QVBoxLayout* pVBoxChannel = new QVBoxLayout;
    pVBoxChannel->setSpacing(0);
    QLabel* labelChannelNumber = new QLabel("Channel Number");
    labelChannelNumber->setStyleSheet("border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; border-bottom: 0px;");
    QLabel* labelChannelName = new QLabel("Channel Name");
    labelChannelName->setStyleSheet("border-top-left-radius: 0px; border-top-right-radius: 0px;");
    pVBoxChannel->addWidget(labelChannelNumber);
    pVBoxChannel->addWidget(labelChannelName);

    .... More stuff

    pGridLayoutMain->addLayout(pVBoxChannel,    0, 0, 2, 1);       
    pGridLayoutMain->addLayout(pVBoxModes,      0, 1, 2, 1);                  
    pGridLayoutMain->addLayout(pVBoxAddSub,     0, 2, 2, 1);                  
    pGridLayoutMain->addWidget(labelServoOrder, 0, 3, 1, 8);              
    

    }
    @

    I am not sure where I am going wrong. I got the whole layout working without the scroll area first so I would know that was not an issue. Thanks.

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

      Hi,

      You should rather have something like

      QVBoxLayout set on ChannelView

      Add a QScrollArea to that layout

      Placeholder QWidget with your grid layout

      set placeholder widget in QScrollArea

      Currently your QScrollArea is not set in any layout manager hence its strange size.

      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
      0
      • R Offline
        R Offline
        RRRitchey
        wrote on last edited by
        #3

        Thank you. The layout showed up but no scroll bars. this is what I did:

        @
        pScrollArea = new QScrollArea;
        pScrollArea->setWidgetResizable(true);
        QVBoxLayout* pVBoxMain = new QVBoxLayout(this);
        pVBoxMain->addWidget(pScrollArea);
        QWidget* pPlaceHolder = new QWidget(pScrollArea);
        pGridLayoutMain = new QGridLayout(pPlaceHolder);
        @

        Also, the layout acts funny now. I can dynamically add some comboboxes and now when they are added to a row the whole row squishes down, clipping labels and other stuff as their boxes shrink. This all worked fine before. I am assuming its because I added the VBox as the base layout. It hard to explain but I don't understand how to attach pictures as it asks for a web address.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          RRRitchey
          wrote on last edited by
          #4

          Here are captures of before using only QGridLayout and after using the QScrollArea. !http://i59.tinypic.com/bj5w9j.jpg(QGridLayout Only - No Servos Added)!!http://i58.tinypic.com/287nsxi.jpg(QGridLayout Only - Servos Added)!!http://i62.tinypic.com/2zjkh78.jpg(QScrollArea Used - No Servos Added)!!http://i60.tinypic.com/fdcbvs.jpg(QScrollArea Used - Servos Added)!

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

            And without that line ?

            @pScrollArea->setWidgetResizable(true);@

            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
            0
            • R Offline
              R Offline
              RRRitchey
              wrote on last edited by
              #6

              I tried it both with and without "setWidgetResizable." No scroll bars. No change in behavior. Horizontal size is fixed, adding things squishes the other columns. Without the ScrollArea the right side would grow. I was wondering over the weekend, can you do something so that all tabs on a TabWidget have scroll areas or do you have to do each tab individually?
              Thanks.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                RRRitchey
                wrote on last edited by
                #7

                I got the behavior I wanted by setting the central widget of my mainwindow to the QScrollArea and setting "setWidgetResizable" to true. I then added my tabwidget (subclassed as SF_UnitView) to the ScrollArea. This enabled the ScrollArea on all the tabs. So far this seems to work the way I was hoping.

                My only other issues now is that on the initial tab I have a picture. It maintains its aspect ratio if the window is smaller than the picture but will stretch the picture horizontally but not vertically when the window is sized bigger than its minimum size. Do I need to intercept the resize and adjust it so the aspect is right? Thanks for all your suggestions.

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

                  Your widgets were nested differently than I thought, but anyway, cool you found a solution.

                  Do you mean resize when it's smaller otherwise keep it size ?

                  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
                  0
                  • R Offline
                    R Offline
                    RRRitchey
                    wrote on last edited by
                    #9

                    Actually, resize when the window is larger than the picture so the picture keeps its aspect ratio. When the window is larger than the picture, the picture will stretch horizontally but not vertically causing it to lose its aspect ratio. I don't know much about catching the resize signal at this point but I am guessing I need to adjust the vertical to match the horizontal stretch? Not a huge issue now but would make it look nicer in the end. Thanks,

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

                      How did you setup that picture ?

                      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
                      0
                      • R Offline
                        R Offline
                        RRRitchey
                        wrote on last edited by
                        #11

                        This is the code for the label. Its placed in an HBox with a spacer on the right side.

                        @ pLabelSF_Logo = new QLabel;
                        pLabelSF_Logo->setMinimumWidth(600);
                        pLabelSF_Logo->setMinimumHeight(232);
                        pLabelSF_Logo->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
                        pLabelSF_Logo->setScaledContents(true);
                        pLabelSF_Logo->setPixmap(QPixmap("../SFPackage/Smart-Fly_Logo3.jpg"));
                        @

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

                          Then you should rather create your own e.g QFrame and draw the image yourself so you can scale it as wanted

                          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
                          0
                          • R Offline
                            R Offline
                            RRRitchey
                            wrote on last edited by
                            #13

                            Thanks. At the moment I think thats a bit over my head and I will leave it for later. Thanks for all your input on this thread.

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

                              You're welcome !

                              If your primary problem is solved then please update the thread title prepending [solved] so other forum users may know as solution has been found :)

                              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
                              0

                              • Login

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