23
23
- [ ` FloatingContainerHasWidgetTitle ` ] ( #floatingcontainerhaswidgettitle )
24
24
- [ ` FloatingContainerHasWidgetIcon ` ] ( #floatingcontainerhaswidgeticon )
25
25
- [ ` HideSingleCentralWidgetTitleBar ` ] ( #hidesinglecentralwidgettitlebar )
26
+ - [ ` FocusHighlighting ` ] ( #focushighlighting )
26
27
- [ Styling] ( #styling )
27
28
- [ Disabling the Internal Style Sheet] ( #disabling-the-internal-style-sheet )
28
29
@@ -284,7 +285,8 @@ otherwise (default setting) it displays application icon.
284
285
285
286
### ` HideSingleCentralWidgetTitleBar `
286
287
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.
288
290
This only makes sense for non draggable and non floatable dock widgets and enables
289
291
the creation of some kind of "central" static widget. Because the titlebar is
290
292
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.
299
301
300
302
![ HideSingleCentralWidgetTitleBar false] ( cfg_flag_HideSingleCentralWidgetTitleBar_false.png )
301
303
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
+
302
412
## Styling
303
413
304
414
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
0 commit comments