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. layout->addWidget() creating problems with full screen
Forum Updated to NodeBB v4.3 + New Features

layout->addWidget() creating problems with full screen

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 1.0k Views 2 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
    Rahem027
    wrote on last edited by Rahem027
    #1

    I have a dock widget with a bunch of line edits and radio buttons. This is my create dock function which creates and shows the dock:

    //initialize main layout of dock
        layout = new QVBoxLayout;
    
        //initialize dock
        QDockWidget *dock = new QDockWidget("Filters", this);
        dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
        dock->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable);
    
        //make group boxes
        QWidget *filters = new QWidget(this);
    
        //only show book which are not returned yet
        notReturnedOnly = new QCheckBox("Only Show books which are not returned");
        connect(notReturnedOnly, &QCheckBox::clicked, this, &LogWindow::onNotReturnedClicked);
        layout->addWidget(notReturnedOnly);
    
        createHistory();
        createIssuedBy();
        createBookIssued();
        createClassGroup();
        createRack();
        createPublisher();
    
        //resetFilters
        resetFilters = new QPushButton("Reset Filters");
        connect(resetFilters, &QPushButton::clicked, this, &LogWindow::reset);
        layout->addWidget(resetFilters, 0, Qt::AlignCenter);
    
        filters->setLayout(layout);
        dock->setWidget(filters);
    
        this->addDockWidget(Qt::RightDockWidgetArea, dock);
        dock->show();
    

    This is my createRack() function definition:

    QGroupBox *rackFilter = new QGroupBox("Rack Number");
        rack = new QLineEdit;
        QHBoxLayout *rackLayout = new QHBoxLayout;
        rackLayout->addWidget(rack);
        rackFilter->setLayout(rackLayout);
    
        //layout->addLayout(tempLayout);
    
        connect(rack, &QLineEdit::editingFinished, this, &LogWindow::onRackNumberEntered);
    
        completeRack = new QCompleter(rackModel);
        completeRack->setCaseSensitivity(Qt::CaseInsensitive);
        completeRack->setCompletionColumn(0);
        rack->setCompleter(completeRack);
    

    The window is shown using `this->showMaximized() .

    If I uncomment the line:
    layout->addWidget()

    The window shows up like this: 0_1529479971612_screenshot.png .

    Interestingly, If I remove any one widget from the dock, the program runs perfectly fine.

    1 Reply Last reply
    0
    • Prince_0912P Offline
      Prince_0912P Offline
      Prince_0912
      wrote on last edited by Prince_0912
      #2

      Hi @Rahem027 ,
      In some cases, it is relevant when a layout is added to a widget. When you set the widget of a QDockWidget or a QScrollArea (with QDockWidget::setWidget() and QScrollArea::setWidget()), the layout must already have been set on the widget. If not, the widget will not be visible.
      This might helpful to you.
      layout->addStretch(1);

      R 1 Reply Last reply
      0
      • Prince_0912P Prince_0912

        Hi @Rahem027 ,
        In some cases, it is relevant when a layout is added to a widget. When you set the widget of a QDockWidget or a QScrollArea (with QDockWidget::setWidget() and QScrollArea::setWidget()), the layout must already have been set on the widget. If not, the widget will not be visible.
        This might helpful to you.
        layout->addStretch(1);

        R Offline
        R Offline
        Rahem027
        wrote on last edited by
        #3

        @Prince_0912 I didnt get you

        Prince_0912P 1 Reply Last reply
        0
        • Prince_0912P Offline
          Prince_0912P Offline
          Prince_0912
          wrote on last edited by
          #4

          @Rahem027 You have to set layout size policy before adding widgets to layout.

          R 1 Reply Last reply
          0
          • Prince_0912P Prince_0912

            @Rahem027 You have to set layout size policy before adding widgets to layout.

            R Offline
            R Offline
            Rahem027
            wrote on last edited by
            #5

            @Prince_0912 No. Which one should I use?

            1 Reply Last reply
            0
            • R Rahem027

              @Prince_0912 I didnt get you

              Prince_0912P Offline
              Prince_0912P Offline
              Prince_0912
              wrote on last edited by Prince_0912
              #6

              @Rahem027 I had same problem as your but i solve this in different manner.
              I take one button and one groupbox.

              in loading form i hide by,
              ui->groupBox_mrr->hide();

              in button click event i put,
              ui->groupBox_mrr->setVisible(!ui->groupBox_mrr->isVisible());1_1529481005294_Untitled1.png 0_1529481005293_Untitled.png

              See the property window in this photo.

              0_1529481137300_Untitled3.png

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

                From what I interpreted, I set the size policy of my dockWidget: horizontal is now fixed and vertical, i set to expanding. But the window remains the same.

                PS: forgive me if I didn't understand what you said.

                1 Reply Last reply
                0
                • Prince_0912P Offline
                  Prince_0912P Offline
                  Prince_0912
                  wrote on last edited by Prince_0912
                  #8

                  @Rahem027 ,
                  In my case initially my GroupBox is hide by setting
                  ui->groupBox_mrr->hide();

                  After that when i click on Mirror Button then GroupBox is appear on display. for that on click function i put,
                  ui->groupBox_mrr->setVisible(!ui->groupBox_mrr->isVisible());

                  if you click again in button then GroupBox is hide.

                  last for the sizepolicy i send you last one photo see ,
                  parameter of SizePolicy , minimumSize , MaximumSize what i set there.

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    Rahem027
                    wrote on last edited by
                    #9

                    Cant everything be shown at once? It is important

                    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