Results 1 to 4 of 4

Thread: Is it possible to put footer in the same line of legend?

  1. #1
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Is it possible to put footer in the same line of legend?

    Hi All,

    I need add a label under the plot, and the footer seems what I need.
    But I don't want the label occupy an extra line. That is I hope put the lable in the same line of legend. and the legend should be right alignment. Just like this:
    Untitled.png

    Any advice/hint is appreciated.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Is it possible to put footer in the same line of legend?

    Unfortunately I don't see an easy solution out of the box.


    • You could manually add a QLabel with your footer text and align it manually according to resize events of the legend. When using QwtPlotRenderer you have to add some code for your footer too.
    • Another option might be to overload QwtPlotLayout::activate() and manipulate the rects for footer and legend.
    • You could also derive from QwtLegend and try to add your footer there


    Uwe

  3. The following user says thank you to Uwe for this useful post:

    freshairfly (22nd January 2014)

  4. #3
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to put footer in the same line of legend?

    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 

  5. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Is it possible to put footer in the same line of legend?

    To make it complete you would also have to overload QwtLegend::renderLegend adding some code for your footer. Otherwise your footer will be missing, when using QwtPlotRenderer ( f.e. for generating pdf documents ).

    Uwe

  6. The following user says thank you to Uwe for this useful post:

    freshairfly (22nd January 2014)

Similar Threads

  1. Replies: 2
    Last Post: 14th March 2012, 09:27
  2. QTableView with summary footer
    By skuda in forum Qt Programming
    Replies: 8
    Last Post: 12th September 2011, 09:19
  3. Printing header and footer with different data
    By sepeth in forum Qt Programming
    Replies: 1
    Last Post: 19th February 2009, 21:51
  4. How to add a footer (QHeaderView) to a QTreeView?
    By DigiDrag in forum Qt Programming
    Replies: 1
    Last Post: 24th September 2008, 00:38
  5. Header and Footer
    By vermarajeev in forum Qt Programming
    Replies: 11
    Last Post: 8th December 2006, 13:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.