layout->addWidget() creating problems with full screen



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



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



  • @Prince_0912 I didnt get you



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



  • @Prince_0912 No. Which one should I use?



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



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



  • @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.



  • Cant everything be shown at once? It is important


Log in to reply
 

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