Uwe,

I'd done it by your advice#3. And it works as expected exactly.
Thank you very much.

Qt Code:
  1. TrendPlotLegend::TrendPlotLegend(QWidget* parent)
  2. : QwtLegend(parent)
  3. {
  4. contentsWidget()->layout()->setAlignment(Qt::AlignRight | Qt::AlignTop);
  5.  
  6. QHBoxLayout* hbLayout = new QHBoxLayout(this);
  7. hbLayout->setContentsMargins(10, 0, 5, 0);
  8. hbLayout->setSpacing(0);
  9.  
  10. m_footer = new QLabel(this);
  11. hbLayout->addWidget(m_footer, 0, Qt::AlignTop);
  12.  
  13. // the old layout is a QVBoxLayout/ replace it with QHBoxLayout
  14. QLayout* oldLayout = layout();
  15. for (int i = 0; i < oldLayout->count(); ++i) {
  16. hbLayout->addItem(oldLayout->takeAt(i));
  17. }
  18. delete oldLayout;
  19. setLayout(hbLayout);
  20. }
  21.  
  22. QSize TrendPlotLegend::sizeHint() const
  23. {
  24. QSize size = QwtLegend::sizeHint();
  25.  
  26. int width = size.width() + m_footer->sizeHint().width();
  27. size.setWidth(qMax(parentWidget()->width(), width));
  28. return size;
  29. }
To copy to clipboard, switch view to plain text mode