I have a QMainWIndow with several widgets, one of which is a QTableView.
The Main WIndow is resizable.
How do I resize the contents of the window automatically, the font and everything, i.e. when the window is resized, its contents should also get resized automatically?
I'd appreciate the help, thanks.
you should put all of your widgets into a layout, layout(s) automatically resize all of your widget(s) inside QMainWindow when user made any change in QMainWindow's size, you can add layout both via Qt Creator IDE and Coding.
UPDATE:
if you add layouts in Qt Creator, layouts automatically coded in moc file and no need to made any changes in their behaviour via coding by user.
but via coding in class constructor:
QVBoxLayout *layout = new QVBoxLayout(parent);
layout->addWidget(widget1);
layout->addWidget(widget2);
layout->addWidget(widget3);
this->setLayout(layout);
but if want to change QLabel's font, this is done by resizeEvent in QMainWindow, so for any change in size of MainWindow, resizeEvent triggered, so you use this code:
in mainwindow.h you declare resizeEvent:
protected:
void resizeEvent(QResizeEvent* event);
in mainwindow.cpp implement resizeEvent:
void MainWindow::resizeEvent(QResizeEvent *event)
{
MainWindow::resizeEvent(event);
if(this)
{
// QLabel process
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With