Neither I could find a tutorial-like scheme for a resize event on QMainWindow, nor I did see any option for adding resize event in the drop-down menu at the Qt design window.
I am new to Qt. I'd like to write a slot function for a QMainWindow resize event. Is there such event? How can I do this?
There is a resize event. In order to perform custom handling of the event, you'll need to create your own resize event handler. In your case, you would need to create a class that derives from QMainWindow
and reimplement the resizeEvent
function. Your code would look something like this:
void MyMainWindow::resizeEvent(QResizeEvent* event) { QMainWindow::resizeEvent(event); // Your code here. }
The Qt Scribble example also has an example of overriding the resize event (though not on the main window).
This works in Qt5 with me f.e. to resize the icon in a QTableWidget:
mainWindow.h ... private: void resizeEvent(QResizeEvent*); ... mainWindow.cpp ... void mainWindow::resizeEvent(QResizeEvent*) { tableWidget->setIconSize(QSize(tableWidget->size()/7)); //7 or whatever number you need it to get the full icon size }
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