spud
2nd October 2007, 17:04
I am trying to catch the hide/show events in a widget which has been placed in a QDockWidget. The problem is that after I tabify the Dockwidget, it doesn't get those notifications anymore when I switch tabs. This behaviour differs from that of an ordinary QTabWidget.
I am using Qt 4.3.0 at the moment and I would like to know if this is wanted behaviour, or if it has been fixed in the 4.4 branch, otherwise I'll file a bug report.
Here is an example to test the behaviour:
#include <QtGui>
class MyLabel : public QLabel
{
public:
MyLabel()
: timesHidden(0)
, timesShown(0)
{
}
void showEvent(QShowEvent*)
{
timesShown++;
QString text;
text.sprintf("Times hidden: %d\nTimes Shown: %d", timesHidden, timesShown);
setText(text);
}
void hideEvent(QHideEvent*)
{
timesHidden++;
}
int timesHidden;
int timesShown;
};
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QMainWindow window;
window.setCentralWidget(new QTextEdit(&window));
QList<QDockWidget*> dockWidgets;
for (int i=1;i<=3;i++){
QDockWidget* dock = new QDockWidget(QString::number(i), &window);
dock->setWidget(new MyLabel);
window.addDockWidget(Qt::BottomDockWidgetArea, dock);
dockWidgets << dock;
}
window.tabifyDockWidget(dockWidgets[1], dockWidgets[2]);
window.show();
return app.exec();
}
I am using Qt 4.3.0 at the moment and I would like to know if this is wanted behaviour, or if it has been fixed in the 4.4 branch, otherwise I'll file a bug report.
Here is an example to test the behaviour:
#include <QtGui>
class MyLabel : public QLabel
{
public:
MyLabel()
: timesHidden(0)
, timesShown(0)
{
}
void showEvent(QShowEvent*)
{
timesShown++;
QString text;
text.sprintf("Times hidden: %d\nTimes Shown: %d", timesHidden, timesShown);
setText(text);
}
void hideEvent(QHideEvent*)
{
timesHidden++;
}
int timesHidden;
int timesShown;
};
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QMainWindow window;
window.setCentralWidget(new QTextEdit(&window));
QList<QDockWidget*> dockWidgets;
for (int i=1;i<=3;i++){
QDockWidget* dock = new QDockWidget(QString::number(i), &window);
dock->setWidget(new MyLabel);
window.addDockWidget(Qt::BottomDockWidgetArea, dock);
dockWidgets << dock;
}
window.tabifyDockWidget(dockWidgets[1], dockWidgets[2]);
window.show();
return app.exec();
}