窗口的某些属性的状态发生改变时就会触发该事件
对应的事件类型包括
- QEvent::ToolBarChange,
- QEvent::ActivationChange,
- QEvent::EnabledChange,
- QEvent::FontChange,
- QEvent::StyleChange,
- QEvent::PaletteChange,
- QEvent::WindowTitleChange,
- QEvent::IconTextChange,
- QEvent::ModifiedChange,
- QEvent::MouseTrackingChange,
- QEvent::ParentChange,
- QEvent::WindowStateChange,
- QEvent::LanguageChange,
- QEvent::LocaleChange,
- QEvent::LayoutDirectionChange
- QEvent::ReadOnlyChange
需要重写的函数为:
void QWidget::changeEvent(QEvent *event)
这里以WindowStateChange为例来说明
窗口刚出现时,窗口状态为Qt::WindowNoState
点击最大化按钮,窗口状态变为Qt::WindowMaximized
点击最小化按钮时,窗口状态变为Qt::WindowMinimized
每次状态改变时,弹出对话框提示
代码如下:
void changeEvent(QEvent* ev){//如果窗口状态发生了改变if(ev->type()==QEvent::WindowStateChange){//如果窗口为最大化if(this->windowState().testFlag(Qt::WindowMaximized)){QMessageBox::information(this,"","is max!");}else if(this->windowState().testFlag(Qt::WindowMinimized)){QMessageBox::information(this,"","is mini!");}else if(this->windowState().testFlag(Qt::WindowNoState)){QMessageBox::information(this,"","is normal!");}}else if(ev->type()==QEvent::WindowTitleChange){}//....还有其他改变类型}
学习链接:https://github.com/0voice