Results 1 to 6 of 6

Thread: Accessing Individual Elements of QwtLegend

  1. #1
    Join Date
    Sep 2012
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Accessing Individual Elements of QwtLegend

    Hello,

    I am new to Qwt and Qt and require using Qwt to draw a minimum of 15 plots, however I needed to fix the size of the qwtplot. Setting the size of the qwtplot does not adjust the size of the legend. The large number of plots thus results in a large legend accompanied by a scrollbar which is undesirable. Setting the font size of the legend items also does not solve the issue. I would like to know how to access individual legend items in order to set their spacing to zero. Converting the legend to a list like:

    QList<QWidget*> this->legend()->legendItems(), gives a list of QWidgets and not QwtLegendItems and hence I cannot use the method setSpacing to set their spacing.

    I would further like to access individual legendItems to use their signals (clicked()) in order to highlight individual plots. Both of these problems can be solved if I would know how to access the legendItems.

    Please do help me out.
    Last edited by kedar; 26th September 2012 at 02:54.

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

    Default Re: Accessing Individual Elements of QwtLegend

    I am new to Qwt and Qt and require using Qwt to draw a minimum of 15 plots, ...
    Guess you mean one plot with a minimum of 15 curves ?

    ...however I needed to fix the size of the qwtplot.
    The legend is part of a QwtPlot widget - guess you mean you want to have a minimum size for the plot canvas. If true the ratio parameter of QwtPlot::insertLegend might be what you are looking for.

    The large number of plots thus results in a large legend accompanied by a scrollbar which is undesirable.
    And what type of legend would you like to have instead ?

    I would further like to access individual legendItems to use their signals (clicked()) in order to highlight individual plots.
    See:

    Qt Code:
    1. QwtPlot::legendClicked( QwtPlotItem * );
    To copy to clipboard, switch view to plain text mode 
    Uwe

  3. #3
    Join Date
    Sep 2012
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Accessing Individual Elements of QwtLegend

    Thanks for replying Uwe,

    And what type of legend would you like to have instead ?
    I apologize for not making myself clear (and for my English). My application consists of drawing a minimum of 15 curves on a single plot. As the number of curves increases, the plot does get cluttered and even though I use some intelligent technique to assign each curve a color, it is impossible to make out which curve say 'x' in the legend corresponds to a curve in the plot. Hence I needed to use signals that when a given legendItem is clicked, the respective curve gets thickened.

    I did try changing the aspect ratio of the legend;

    QwtLegend* legend = this->legend();
    this->insertLegend(legend,QwtPlot::RightLegend,0.3);

    I am not sure of how the ratio affects the legend because below 0.1 the legend just disappears and above this the aspect ratio remains same. The size of the curve is 500 px by 500 px and more than 20 items do not fit in this space, a scrollbar is thus created. Is there a way to fix the spacing between the legend items, so as to avoid this from happening. Please see the attached snapshot (ignore the naming of the curves, there are about 33 in this plotplots1.png)


    Thanks

    Kedar

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Accessing Individual Elements of QwtLegend

    The legend (or actually its contentsWidget) has a layout thus you should be able to access it and reduce the spacing.

    This should work:
    Qt Code:
    1. QwtLegend *legend = ...;
    2. legend->contentsWidget()->layout()->setSpacing(1); // or 0
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: Accessing Individual Elements of QwtLegend

    Also each legend item has a margin of 4 pixels, that can be modified by QwtTextLabel::setMargin().

    Uwe

  6. #6
    Join Date
    Sep 2012
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Accessing Individual Elements of QwtLegend

    Thanks Uwe, Wysota. Works for me.


    Kedar

Similar Threads

  1. Accessing complete QWebFrame document tree, not just elements
    By TimShnaider in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2012, 03:37
  2. Accessing elements of a svg file
    By Hogwarts in forum Qt Programming
    Replies: 2
    Last Post: 22nd February 2011, 14:00
  3. accessing table elements in Qt
    By awanish_jmi in forum Newbie
    Replies: 5
    Last Post: 28th July 2008, 12:51
  4. dealing individual objects
    By kingslee in forum General Programming
    Replies: 9
    Last Post: 15th November 2006, 01:28
  5. accessing gui elements from parent
    By chemstar in forum Qt Programming
    Replies: 3
    Last Post: 21st May 2006, 11:22

Tags for this Thread

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.