Uwe,
I'd done it by your advice#3. And it works as expected exactly.
Thank you very much.
TrendPlotLegend
::TrendPlotLegend(QWidget* parent
){
contentsWidget()->layout()->setAlignment(Qt::AlignRight | Qt::AlignTop);
hbLayout->setContentsMargins(10, 0, 5, 0);
hbLayout->setSpacing(0);
hbLayout->addWidget(m_footer, 0, Qt::AlignTop);
// the old layout is a QVBoxLayout/ replace it with QHBoxLayout
for (int i = 0; i < oldLayout->count(); ++i) {
hbLayout->addItem(oldLayout->takeAt(i));
}
delete oldLayout;
setLayout(hbLayout);
}
QSize TrendPlotLegend
::sizeHint() const {
int width = size.width() + m_footer->sizeHint().width();
size.setWidth(qMax(parentWidget()->width(), width));
return size;
}
TrendPlotLegend::TrendPlotLegend(QWidget* parent)
: QwtLegend(parent)
{
contentsWidget()->layout()->setAlignment(Qt::AlignRight | Qt::AlignTop);
QHBoxLayout* hbLayout = new QHBoxLayout(this);
hbLayout->setContentsMargins(10, 0, 5, 0);
hbLayout->setSpacing(0);
m_footer = new QLabel(this);
hbLayout->addWidget(m_footer, 0, Qt::AlignTop);
// the old layout is a QVBoxLayout/ replace it with QHBoxLayout
QLayout* oldLayout = layout();
for (int i = 0; i < oldLayout->count(); ++i) {
hbLayout->addItem(oldLayout->takeAt(i));
}
delete oldLayout;
setLayout(hbLayout);
}
QSize TrendPlotLegend::sizeHint() const
{
QSize size = QwtLegend::sizeHint();
int width = size.width() + m_footer->sizeHint().width();
size.setWidth(qMax(parentWidget()->width(), width));
return size;
}
To copy to clipboard, switch view to plain text mode
Bookmarks