Qt resize event for docks

孤街浪徒 提交于 2019-12-06 02:58:40

问题


Is there a way to catch resize events for docks in Qt? I need to be able to detect when a dock is resized (and not only when its location or 'features' change). It looks like there is no 'resized' signal for QDockWidget.


回答1:


If you do not wish to subclass to just get resize event control, you can installEventFilter

Small example would look like (MainWindow.h): (MainWindow holds DockWidget Here)

protected:
  bool eventFilter(QObject *obj, QEvent *event);

and in (MainWindow.cc):

MainWindow::MainWindow(QWidget* parent)
    : QWidget(parent) {
  ui_.setupUi(this);
  ui_.dockWidget->installEventFilter(this);
}

bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
  if (event->type() == QEvent::Resize && obj == ui_.dockWidget) {
      QResizeEvent *resizeEvent = static_cast<QResizeEvent*>(event);
      qDebug("Dock Resized (New Size) - Width: %d Height: %d",
             resizeEvent->size().width(),
             resizeEvent->size().height());
  } 
  return QWidget::eventFilter(obj, event);
}


来源:https://stackoverflow.com/questions/15331854/qt-resize-event-for-docks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!