Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign callback when the user resizes a QMainWindow?

Tags:

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?

like image 822
Barney Szabolcs Avatar asked Oct 10 '12 21:10

Barney Szabolcs


2 Answers

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).

like image 117
RA. Avatar answered Oct 13 '22 09:10

RA.


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 } 
like image 29
Ingo Mi Avatar answered Oct 13 '22 09:10

Ingo Mi