Label does not resize with resizeEvent

  • lbl = new QLabel( ui->centralWidget);

    How do i resize this label using resizeEvent . When i put this code in void Mainwindow :: resizeEvent(QreseizeEvent *evt) ; it stays the same. The size does not change.

    Please give me a proper explanation about resize event.

    Thank you.

  • Lifetime Qt Champion

    @ronyNS said:


    Its called when mainwindow change size.

    To size a qlabel
    you do
    lbl->setGeometry(0,0, event->size().width(), event->size().height());
    to use the mainwindow values

  • It fits the window size , but does not resize when i maximize the window

    My code

    Void MainWindow :: resizeEvent(QResizeEvent *event)
    lbl = new QLabel (ui->centralWidget);
    Int x = MainWindow::size().height();
    Int y = MainWindow::size().width();

  • Qt Champions 2018

    @ronyNS Why not use a layout for that? I just tried: added a label to main window and set the layout in main window: label is resized even if I maximize window.

Log in to reply

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