Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt resize event for docks

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.

like image 474
J. V. Avatar asked Mar 11 '13 05:03

J. V.


1 Answers

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);
}
like image 61
Viv Avatar answered Oct 15 '22 01:10

Viv