Skip to content

Commit 0c13402

Browse files
Added documentation for FocusHighlighting flag
1 parent 97e3d72 commit 0c13402

File tree

4 files changed

+113
-2
lines changed

4 files changed

+113
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ by the following people:
137137

138138
- [n-elie](https://github.com/n-elie)
139139
- [Hugo Slepicka](https://github.com/hhslepicka)
140+
- [K Lauer](https://github.com/klauer)
140141

141142
Latest working version: [3.4.2](https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System/releases/tag/3.4.2)
142143

doc/cfg_flag_FocusHighlighting.gif

158 KB
Loading

doc/user-guide.md

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- [`FloatingContainerHasWidgetTitle`](#floatingcontainerhaswidgettitle)
2424
- [`FloatingContainerHasWidgetIcon`](#floatingcontainerhaswidgeticon)
2525
- [`HideSingleCentralWidgetTitleBar`](#hidesinglecentralwidgettitlebar)
26+
- [`FocusHighlighting`](#focushighlighting)
2627
- [Styling](#styling)
2728
- [Disabling the Internal Style Sheet](#disabling-the-internal-style-sheet)
2829

@@ -284,7 +285,8 @@ otherwise (default setting) it displays application icon.
284285

285286
### `HideSingleCentralWidgetTitleBar`
286287

287-
If there is only one single visible dock widget in the main dock container (the dock manager) and if this flag is set, then the titlebar of this dock widget will be hidden.
288+
If there is only one single visible dock widget in the main dock container (the dock manager)
289+
and if this flag is set, then the titlebar of this dock widget will be hidden.
288290
This only makes sense for non draggable and non floatable dock widgets and enables
289291
the creation of some kind of "central" static widget. Because the titlebar is
290292
hidden, it is not possible to drag out the central widget to make it floating
@@ -299,6 +301,114 @@ still has a titlebar to drag it out of the main window.
299301

300302
![HideSingleCentralWidgetTitleBar false](cfg_flag_HideSingleCentralWidgetTitleBar_false.png)
301303

304+
### `FocusHighlighting`
305+
306+
If this is enabled, the docking system is able to highlight the tab and the
307+
components of a dock area with a different style (i.e. a different color).
308+
This option is disabled by default and needs to be enabled explicitely
309+
because it adds some overhead. The dock manager needs to react on focus
310+
changes and dock widget dragging to highlight the right dock widget. You should
311+
enable it only, if you really need it for your application.
312+
313+
If the feature is enabled, you can also connect to the new dock manager
314+
signal `focusedDockWidgetChanged(CDockWidget* old, CDockWidget* now)` to
315+
react on focus changes and to prepare the content of the focused dock
316+
widget.
317+
318+
You can click into the tab, the titlebar or the content of a dock widget
319+
to focus it.
320+
321+
![FocusHighlighting](cfg_flag_FocusHighlighting.gif)
322+
323+
For the focused dock widget and dock widget tab, the property `focused` will
324+
be set to true and you can use this property to style the focused dock
325+
widget differently. The picture above uses the following styling:
326+
327+
```css
328+
/* Color the tab with the nhighlight color */
329+
ads--CDockWidgetTab[focused="true"]
330+
{
331+
background: palette(highlight);
332+
border-color: palette(highlight);
333+
}
334+
335+
/* Use a different colored close button icon to match the test color */
336+
ads--CDockWidgetTab[focused="true"] > #tabCloseButton
337+
{
338+
qproperty-icon: url(:/ads/images/close-button-focused.svg)
339+
}
340+
341+
/* Make a hovered focused close button a little bit lighter */
342+
ads--CDockWidgetTab[focused="true"] > #tabCloseButton:hover
343+
{
344+
background: rgba(255, 255, 255, 48);
345+
}
346+
347+
/* Make a pressed focused close button even more lighter */
348+
ads--CDockWidgetTab[focused="true"] > #tabCloseButton:pressed
349+
{
350+
background: rgba(255, 255, 255, 92);
351+
}
352+
353+
/* Use a different color for the tab label */
354+
ads--CDockWidgetTab[focused="true"] QLabel
355+
{
356+
color: palette(light);
357+
}
358+
359+
/* Paint a nice solid line for the whole title bar to create the illusion
360+
of an active tab */
361+
ads--CDockAreaWidget[focused="true"] ads--CDockAreaTitleBar
362+
{
363+
background: transparent;
364+
border-bottom: 2px solid palette(highlight);
365+
padding-bottom: 0px;
366+
}
367+
```
368+
369+
If you have a content widget that does not support focussing for some reason
370+
(like `QVTKOpenGLStereoWidget` from the [VTK library](https://github.com/Kitware/VTK)),
371+
then you can manually switch the focus by reacting on mouse events. The
372+
following code shows, how to install en event filter on the `QVTKOpenGLStereoWidget`
373+
to properly switch the focus on `QEvent::MouseButtonPress`:
374+
375+
```c++
376+
static ads::CDockWidget* createVTK2DWindow(QMenu* ViewMenu, QObject* EventFilter)
377+
{
378+
QVTKOpenGLStereoWidget* qvtkOpenGLStereoWidget = new QVTKOpenGLStereoWidget;
379+
ads::CDockWidget* DockWidget = new ads::CDockWidget("2D Window");
380+
DockWidget->setWidget(qvtkOpenGLStereoWidget);
381+
qvtkOpenGLStereoWidget->installEventFilter(EventFilter);
382+
qvtkOpenGLStereoWidget->setProperty("DockWidget", QVariant::fromValue(DockWidget));
383+
return DockWidget;
384+
}
385+
```
386+
387+
Now we can use the event filter function to react on mouse events and then
388+
use the dock manager function `setDockWidgetFocused()` to switch the focus:
389+
390+
```c++
391+
bool CMainWindow::eventFilter(QObject *watched, QEvent *event)
392+
{
393+
if (event->type() == QEvent::MouseButtonPress)
394+
{
395+
QVTKOpenGLStereoWidget* vtkWidget = qobject_cast<QVTKOpenGLStereoWidget*>(watched);
396+
auto vDockWidget = vtkWidget->property("DockWidget");
397+
ads::CDockWidget* DockWidget = nullptr;
398+
if (vDockWidget.isValid())
399+
{
400+
DockWidget = qvariant_cast<ads::CDockWidget*>(vDockWidget);
401+
}
402+
403+
if (DockWidget)
404+
{
405+
d->DockManager->setDockWidgetFocused(DockWidget);
406+
}
407+
}
408+
return false;
409+
}
410+
```
411+
302412
## Styling
303413

304414
The Advanced Docking System supports styling via [Qt Style Sheets](https://doc.qt.io/qt-5/stylesheet.html). All components like splitters, tabs, buttons, titlebar and

src/stylesheets/default.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ ads--CDockSplitter::handle
105105

106106
/* Focus related styling */
107107
ads--CDockWidgetTab[focused="true"]
108-
{;
108+
{
109109
background: palette(highlight);
110110
border-color: palette(highlight);
111111
}

0 commit comments

Comments
 (0)