PDA

View Full Version : odd failure while adding custom widgets to QDockWidget



sai
25th November 2008, 02:59
I want to add several widgets to a single dockwidget.
As the QDockWidget owns no "addWidget" function, I managed to add a widgetForDock widget to it using "setWidget" function, and make other widgets children of the widgetForDock.

eg:
dockWidget->setWidget(widgetForDock);

It works well, when I make it through toward the Qt widgets, such as QLineEdit and QGroupBox. However, when I add my own object of class HistogramView, derived from QWidget, it fails to show.

eg: fail


QVBoxLayout *layout = new QVBoxLayout(widgetForDock);
HistogramView *histView = new HistogramView();
layout->addWidget(histView);

class HistogramView : public QWidget
{
...
public:
HistogramPlotter *histPlotter;
QWidget *widget;
}

The even odder thing is that, when I add the object histView itselft to the dockWidget, it fails, while the public members (histPlotter and widget) are added to it, it works well!

eg: works!


layout->addWidget(histView->histPlotter);
layout->addWidget(histView->widget);

The HistogramPlotter is a cumter widget, also derived from the QWidget, just as its owner object do.

jacek
26th November 2008, 23:37
Does this custom widget work OK if you add it to a normal widget? Could you post the HistogramView::HistogramView() code?

sai
27th November 2008, 04:20
Thanks a lot for your care.
I've tried to put HistogramView's object into QGroupBox's layout, and it follows the same problem:
when HistogramView's object itself added in , it fails, while the public member added in , it works well !


class HistogramView : public QWidget
{
Q_OBJECT
public:
HistogramView(QWidget *parent = 0);
HistogramView(const QImage &image, QWidget *parent = 0);
signals:
...
private slots:
...
public:
HistogramPlotter *histPlotter;
QWidget *widget;
...
}

jacek
28th November 2008, 00:46
What do you do with "parent" in the constructor?

sai
2nd December 2008, 04:19
it's passed to the object's parent, QWidget, for initialization