Results 1 to 6 of 6

Thread: Is it possible to get a legend ID using QwtLegend?

  1. #1
    Join Date
    Feb 2012
    Location
    Stuttgart / Germany
    Posts
    35
    Thanks
    6
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Is it possible to get a legend ID using QwtLegend?

    Hello,

    I'm using QwtLegend to insert legends in my plot area, I setted my legend as CheckableItem and I added a connection:

    Qt Code:
    1. connect(plot.at(iPlotCounter), SIGNAL(legendChecked(QwtPlotItem *, bool)),this,
    2. SLOT(setConfig(QwtPlotItem *, bool)));
    To copy to clipboard, switch view to plain text mode 

    Normally my plot has 8 curves and there is a possibility that two curves have the same legend name (the same title). I know it's possible to get the name when I click on one legend:

    Qt Code:
    1. void MainWindow::setConfig(QwtPlotItem * te, bool ta)
    2. {
    3. if (ta==true)
    4. {
    5. qDebug() << te->title().text() << "\n";
    6. qDebug() << te-> << "\n";
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    But because of the problem that I can have two legends with the same name, get the name doesn't help me so much. So, I was wondering if there is a possibility to get an ID, for example, when I add each legend, maybe there is a value for each, in my case 8, maybe an ID that comes from 0 to 7, I don't know.

    Anyone knows if is there an ID, a specific number for each legend or the only possibility is using the name?

    Thanks in advance
    Best Regards

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Is it possible to get a legend ID using QwtLegend?

    Try using z-order (QwtPlotItem::z()).
    If it won't work out-of-a-box try setting z-order when creating the curve and then retreiving it later.
    It's not foolproof as anything can change it but always something.

  3. #3
    Join Date
    Feb 2012
    Location
    Stuttgart / Germany
    Posts
    35
    Thanks
    6
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Is it possible to get a legend ID using QwtLegend?

    Hi,

    I didn't work for what I want. I was trying to do this:

    Qt Code:
    1. void MainWindow::setConfig(QwtPlotItem * te, bool ta)
    2. {
    3. if (ta==true)
    4. {
    5. QList<QWidget*> t = plot.at(iPlotCounter)->legend()->legendItems();
    6. for (int i=0; i<t.size(); i++)
    7. {
    8. qDebug() << "Name: " << ((QwtLegendItem *)t[i])->text().text() << "\n";
    9. qDebug() << "Checked: " << ((QwtLegendItem *)t[i])->isChecked() << "\n";
    10. }
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    The problem is: when I use QList, I don't know why (maybe you can explain me), my list gets unsorted, for example, my legend's names are:

    Current
    Voltage
    Voltage
    Charge
    Discharge
    Total

    I was expecting that my list order would be the same and then I could use the index as my index, but when I get the list, it's always in a different order.

    After this problem I was trying to find any information that I could use, inside of this legendItems that I got, I found a variable that calls "ser_no", I don't know how to take the value of this variable, but it seems to be what I need, because the values are increasing according by the plotted order, then I could use them as my index.

    Ok, I have three other questions:
    First: Is it possible to create a QList using (QList<QWidget*> t = plot.at(iPlotCounter)->legend()->legendItems() and make sure that the list has the same order that's been showed?
    Second: Why does QList change the order?
    Third: Anyone knows how to get this "ser_no" or what this "ser_no" means?

    Thanks in advance
    Best Regards

  4. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Is it possible to get a legend ID using QwtLegend?

    Hey,

    The legend item list is sorted, but the key is not the text but the pointer to the widget:
    Qt Code:
    1. "Curve 5" QwtLegendItem(0x931ead0)
    2. "Curve 0" QwtLegendItem(0x931eb48)
    3. "Curve 4" QwtLegendItem(0x931ebe8)
    4. "Curve 1" QwtLegendItem(0x931ec10)
    5. "Curve 6" QwtLegendItem(0x931ecb0)
    6. "Curve 3" QwtLegendItem(0x931ef08)
    7. "Curve 2" QwtLegendItem(0x933ad50)
    8. "Curve 7" QwtLegendItem(0x933ae90)
    9. "Curve 8" QwtLegendItem(0x933af30)
    10. "Curve 9" QwtLegendItem(0x933afd0)
    To copy to clipboard, switch view to plain text mode 

    So answer to question 2 is: list doesn't change the order, it's just ordered by something else that you'd expect.

    I don't know where you got the 'ser_no', but I couldn't find it anywhere in qwt 6.0.1 source I have.

    To answer your original question:
    Create additional map of your curves in format: QMap< QwtPlotItem*, int >, where pointer is your curve, and int is its ID (may be index in other list you have or anything else that you find useful);
    this way in your setConfig() you can get ID of each curve from the pointer you're getting there.

    Now I have a question:
    Why do you need it for?
    There may be something wrong with your thinking here.

  5. The following user says thank you to Spitfire for this useful post:

    cesroc (8th June 2012)

  6. #5
    Join Date
    Feb 2012
    Location
    Stuttgart / Germany
    Posts
    35
    Thanks
    6
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Is it possible to get a legend ID using QwtLegend?

    Hello,

    I found a way to get the ser_no.

    Qt Code:
    1. ((QwtLegendItem*)legendList[i])->identifier().serialNumber();
    To copy to clipboard, switch view to plain text mode 

    It's working know, I have the ID I need and I can find which legend even if they have the same name.

    Thanks for your help.
    Bye

  7. #6
    Join Date
    Jun 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Is it possible to get a legend ID using QwtLegend?

    I'm sorry to reopen this topic.

    I have the same problem but QwtLegendItem doesn't exist now with Qwt 6.1.2! Now we only have QwtPlotLegendItem.

    This line is not possible :
    Qt Code:
    1. ((QwtLegendItem*)legendList[i])->identifier().serialNumber();
    To copy to clipboard, switch view to plain text mode 

    I just can do this but it's not ok :
    Qt Code:
    1. QwtPlotItem *plotItem = plot_spectre->infoToItem( itemInfo );
    2. nom_courbe = plotItem->title().text();
    To copy to clipboard, switch view to plain text mode 

    What can i do?

    Maybe put the legend with QwtPlotLegendItem but i don't arrive to put on right the legend as :
    Qt Code:
    1. insertLegend(legend, QwtPlot::RightLegend);
    To copy to clipboard, switch view to plain text mode 
    The legend is inside the plot.

Similar Threads

  1. QwtLegend orientation on QwtPlot
    By bday1223 in forum Qwt
    Replies: 1
    Last Post: 27th September 2011, 07:26
  2. QwtPolarMarker and QwtLegend
    By lokida in forum Qwt
    Replies: 4
    Last Post: 29th March 2011, 10:00
  3. QwtLegend size
    By baray98 in forum Qwt
    Replies: 3
    Last Post: 11th May 2010, 10:55
  4. QwtLegend size
    By baray98 in forum Qwt
    Replies: 0
    Last Post: 10th May 2010, 06:26
  5. Set Title for QWTLegend...
    By umulingu in forum Qwt
    Replies: 3
    Last Post: 23rd March 2010, 10:28

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.