Skip to content

Commit

Permalink
examples: Show how to hide dock indicators when ctrl is pressed
Browse files Browse the repository at this point in the history
Fixes issue #334 and issue #337.
Won't add this directly into the library, as each project
has different requirements regarding this.

It's easy to do in application code though.

(cherry picked from commit af455bb)
  • Loading branch information
iamsergio committed Mar 8, 2023
1 parent 17d166b commit b0836ea
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions examples/dockwidgets/MyMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QDebug>
#include <QString>
#include <QTextEdit>
#include <QWindow>
#include <QRandomGenerator>

#include <QApplication>
Expand Down Expand Up @@ -123,6 +124,9 @@ MyMainWindow::MyMainWindow(const QString &uniqueName, KDDockWidgets::MainWindowO
if (options & KDDockWidgets::MainWindowOption_HasCentralWidget) {
setPersistentCentralWidget(new MyWidget1());
}

// optional, just for demo purposes regarding pressing Ctrl key to hide drop indicators
qApp->installEventFilter(this);
}

MyMainWindow::~MyMainWindow()
Expand Down Expand Up @@ -215,3 +219,26 @@ KDDockWidgets::Views::DockWidget_qtwidgets *MyMainWindow::newDockWidget()
count++;
return dock;
}

bool MyMainWindow::eventFilter(QObject *obj, QEvent *ev)
{
// This event filter is just for examplify how to use the KDDW API to hide
// the drag indicators when ctrl is pressed

switch (ev->type()) {
case QEvent::KeyPress:
case QEvent::KeyRelease: {
auto kev = static_cast<QKeyEvent *>(ev);
if (kev->key() == Qt::Key_Control && qobject_cast<QWindow *>(obj)) {
const bool hideIndicators = ev->type() == QEvent::KeyPress;
KDDockWidgets::Config::self().setDropIndicatorsInhibited(hideIndicators);
}
}

break;
default:
break;
}

return false;
}
1 change: 1 addition & 0 deletions examples/dockwidgets/MyMainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class MyMainWindow : public KDDockWidgets::Views::MainWindow_qtwidgets

private:
void createDockWidgets();
bool eventFilter(QObject *obj, QEvent *ev) override;
KDDockWidgets::Views::DockWidget_qtwidgets *newDockWidget();
QMenu *m_toggleMenu = nullptr;
const bool m_dockWidget0IsNonClosable;
Expand Down

0 comments on commit b0836ea

Please sign in to comment.