1

I have a function that has as a parameter a pointer to a widget. In the function I add the widget in a layout of a frame. I wish to scale the widget at a maximum size because I do not wish to let it resize the frame.

void resizeWidget(QWidget *drawingBoard)
{
    QSize widgetSize = drawingBoard -> size();
    widgetSize.scale(100, 100, Qt::KeepAspectRatio);
    drawingBoard -> setFixedSize(widgetSize);
    ui->layPieceFrameContainerLayout -> addWidget(drawingBoard);
}

The problem is the widget is sectioned and incomplete when displayed in the frame (the frame is displayed at full size and has a size of 400 x 400). If I display the widget without scale the widget is complete. Do anyone see a solution?

student
  • 352
  • 2
  • 15
  • Possible duplicate of [Expanding widget without expanding layout](http://stackoverflow.com/questions/40346004/expanding-widget-without-expanding-layout) – Kevin Krammer Nov 01 '16 at 12:16
  • How is this question different from [this one](http://stackoverflow.com/questions/40346004/expanding-widget-without-expanding-layout)? – Kuba hasn't forgotten Monica Nov 01 '16 at 12:25
  • That is my question. I found out I have another problem when I try another method. I wish to get a fix for it so I presented two methods that need a different solution. – student Nov 01 '16 at 14:54
  • Remember that a `QLayout` will not resize the top-level **window** it's enclosed in, unless you set a size constraint. See e.g. [this answer](http://stackoverflow.com/a/32126902/1329652) and [that one](http://stackoverflow.com/a/21265287/1329652). So, if the widget's size is too large to fit in the enclosing window, the layout will do nothing about it until the constraint is set. Once it is, the window will be resized. The constraint is unnecessary for widgets that are created *before* the window appears: the window will start with a sufficient size to fit the contents. That threw you off. – Kuba hasn't forgotten Monica Nov 01 '16 at 15:10

0 Answers0