Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
4.8.0
-
None
-
MS VisualStudio 2010, SP1
Qt Add-in 1.1.10
Qt 4.7.8
Description
It would be valuable to have the QDockWidget::setWidget() method virtual.
Imagine a dockwidget class with autohide/autoshow functionality like you know it from Visual Studio.
class CHideableDockWidget : public QDockWidget
This could be achieved e.g. with a QStackedWidget and a QTabBar.
The Tabbar will be positioned on the first page of the stacked widget,
and the dockwidgets widget on the second page of the stacked widget.
Then the StackedWidget has to be set as the DockWidgets widget
To perform the autohide or autoshow funcitonality then you can simply
switch the currentIndex of the stackedWidget and change the size of it.
But this requires to overload the setWidget method.
Here is one possible implementation:
void CHideableDockWidget::setWidget(QWidget *widget)
{
while (m_stackedWidget.count() > 0)
m_stackedWidget.addWidget(&m_tabBar);
m_stackedWidget.addWidget(widget);
m_stackedWidget.setCurrentIndex(1);
if (this->widget() != &m_stackedWidget)
{ QDockWidget::setWidget(&m_stackedWidget); }}
This implementation would work with the current Qt version and
QDockWidget setWidget method declaration, but we would hide
the inherited method name and the code would work under certain
circumstances only.
(See Scott Meyers, "Effective C++", Item 33 - Avoid hiding inherited names)