Results 1 to 3 of 3

Thread: More information about QwtLegendLabel

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

    Default More information about QwtLegendLabel

    Hello,

    I am using the legend to show/hide my curve and it works fine.

    But I am looking for a way to set the QwtLegendLabel of the curve to SET when attached to the plot...

    Can someone help me?
    I have not find how to reach easyli QwtLegendLabel of a curve...

    I use this to show/hide:
    Qt Code:
    1. void GraphB::showCurve( QwtPlotItem *item, bool on )
    2. {
    3. // Show/hide the curve
    4. item->setVisible( on );
    5.  
    6. // Get QwtLegend .... but why
    7. QwtLegend *lgd = qobject_cast<QwtLegend *>( legend() );
    8.  
    9. // List of widget from QwtLegend associate to item
    10. QList<QWidget *> legendWidgets =
    11. lgd->legendWidgets( itemToInfo( item ) );
    12.  
    13. // ????
    14. if ( legendWidgets.size() == 1 )
    15. {
    16. // legendLabel is the frame of the legend label
    17. QwtLegendLabel *legendLabel =
    18. qobject_cast<QwtLegendLabel *>( legendWidgets[0] );
    19.  
    20. // If we have the object check it
    21. if ( legendLabel )
    22. legendLabel->setChecked( on );
    23. }
    24.  
    25. replot();
    26. }
    To copy to clipboard, switch view to plain text mode 

    I am also looking for a method to hide the yAxis of the QwtPlotCurve... if someone has already done something

    Thanks
    Sangfeust
    Last edited by Sangfeust; 5th February 2015 at 14:47.

  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: More information about QwtLegendLabel

    tvplot or cpuplot examples show how to access legend labels, axes can be shown/hidden using QwtPlot::enableAxis().

    Uwe

  3. #3
    Join Date
    Jan 2015
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: More information about QwtLegendLabel

    Thanks Uwe for your reply.

    Actually I use this 3 function, but I am looking to have just one... But don't find how. Because it is not all clear for me how to get the legendLabel state.

    //Standard slot call by legendLabel, so why no pointer to the label?
    void GraphB::legendChecked( const QVariant &itemInfo, bool on )
    {
    QwtPlotItem *plotItem = infoToItem( itemInfo );
    if ( plotItem )
    showCurve( plotItem, on );
    }

    //Standard private function called by legendChecked
    void GraphB::showCurve( QwtPlotItem *item, bool on )
    {
    // Montre ou cache la courbe/l'item désiré
    item->setVisible( on );

    // On récupère le QwtLegend ... mais pourquoi faire?
    QwtLegend *lgd = qobject_cast<QwtLegend *>( legend() );

    // On récupère une liste de widget à partir de QwtLegend
    QList<QWidget *> legendWidgets =
    lgd->legendWidgets( itemToInfo( item ) );

    // ????
    if ( legendWidgets.size() == 1 )
    {
    // legendLabel représente la zone de la légende associé à une courbe
    QwtLegendLabel *legendLabel =
    qobject_cast<QwtLegendLabel *>( legendWidgets[0] );

    // Si on a réussi à créer l'objet on check/uncheck
    if ( legendLabel )
    legendLabel->setChecked( on );
    }

    replot();
    }

    //I use this function to set/reset the legendLabel, I just add the "setVisible( on )" function to have the curve as the legend.
    //But I am not sure about the reliability of this funchtion, is there plotItem without "setVisible" method?
    void GraphB::setLegendChecked( QwtPlotItem *plotItem , bool on )
    {
    plotItem->setVisible( on );
    const QwtPlotItemList items = itemList();
    for ( int i = 0; i < items.size(); i++ )
    {
    QwtPlotItem *item = items[ i ];
    if ( item->testItemAttribute( QwtPlotItem::Legend ) )
    {
    QwtLegend *lgd = qobject_cast<QwtLegend *>( legend() );

    QwtLegendLabel *label = qobject_cast< QwtLegendLabel *>(
    lgd->legendWidget( itemToInfo( item ) ) );
    if ( label )
    {
    lgd->blockSignals( true );
    if( item == plotItem )
    label->setChecked( on );//item == plotItem );
    lgd->blockSignals( false );
    }
    }
    }
    }

Similar Threads

  1. Replies: 1
    Last Post: 19th September 2014, 08:56
  2. Replies: 14
    Last Post: 27th November 2011, 14:13
  3. Information regarding QFile
    By Raghaw in forum Qt Programming
    Replies: 2
    Last Post: 12th October 2010, 16:32
  4. QT app information
    By CHeader in forum Qt Programming
    Replies: 5
    Last Post: 4th April 2008, 11:07
  5. Getting MAC Information from qt?
    By vishal.chauhan in forum Qt Programming
    Replies: 4
    Last Post: 23rd May 2007, 09:31

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.