Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Why does the child widget not resize when I call resize () on parent?



  • There is CurveWidgetDialog derived form QDialog and QWidget curveWidget as child (attached picture).0_1547563547966_ыыы.png

    I call method resize() in constructor of CurveWidgetDialog, but child widget ()curveWidget doesn't change size (qDebug() outputs "QSize(100, 30)"). I use folowing code:

    CurveWidgetDialog::CurveWidgetDialog(QWidget *parent) :
    	QDialog(parent),
    	ui(new Ui::CurveWidgetDialog)
    {
    	ui->setupUi(this);
    //...
    	resize(1000, 1000);
    
    	qDebug() << ui->curveWidget->size();
    //...
    }
    

    what the hell?



  • @xruck
    I assume the reason is: What size settings do you have on your CurveWidget which tell it you'd like it to occupy the full size of its parent QDialog?

    Otherwise: It's just possible that resizing in the parent's constructor is too early for the child, though I don't think so.



  • 0_1547566542594_ыыыы.PNG
    Do you mean sizePolicy?


  • Lifetime Qt Champion

    Hi
    Some layout calculation is postponed until widget is shown meaning
    qDebug() << ui->curveWidget->size(); in constructor does not show the new size values.

    So does it visually also NOT use all the space ?
    When CurveWidgetDialog is actually shown on screen.



  • @mrjj
    I create and show dialog in the main.cpp

    int main(int argc, char *argv[])
    {
    	QApplication a(argc, argv);
    
    	CurveWidgetDialog w;
    	w.show();
    
    	return a.exec();
    }
    

    I suppose I need handle QWidget::showEvent() signal to recive size of the widget?


  • Lifetime Qt Champion

    @xruck
    Yes showEvent should give true size.
    So it does use the actual space when shown, and its just the size reporting that is off ?



  • @mrjj Yeah! Fantasstic answer!! Thank you very much!:) We close question [EDIT: Expletives removed --JKSH]


Log in to reply