本文介绍了码头的Qt调整大小事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法可以捕获Qt中停靠站的调整大小事件?我需要能够检测坞站何时调整大小(不仅是其位置或功能"更改时).看来QDockWidget没有调整大小"信号.
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.
推荐答案
如果您不希望仅继承子类来获得调整大小的事件控制,则可以 installEventFilter
If you do not wish to subclass to just get resize event control, you can installEventFilter
小例子看起来像(MainWindow.h
):(MainWindow在此处保存DockWidget)
Small example would look like (MainWindow.h
): (MainWindow holds DockWidget Here)
protected:
bool eventFilter(QObject *obj, QEvent *event);
和(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);
}
这篇关于码头的Qt调整大小事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!