Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to draw draggable custom legend enclosing all the legends items in qt charts
Forum Updated to NodeBB v4.3 + New Features

How to draw draggable custom legend enclosing all the legends items in qt charts

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 177 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sachinrd
    wrote on last edited by
    #1

    Hi,
    I wanted to know as to how i can have the legends of a chart draggable and movable to custom position. I do know that there is an example for making legends position custom. The example name is - "Legend Example". As soon as i detach the legend here, the transparent rectangle is enclosing a larger space than that is needed. how do i enclose the rectangle here only over the legends displayed? Thanks for any help in advance.
    8c004039-cb67-4806-bcae-53cdc70306ac-image.png
    Attached is the code snippet in the qt legend example pertinent to making the legend position custom

            legend->detachFromChart();
            m_chart->legend()->setBackgroundVisible(true);
            m_chart->legend()->setBrush(QBrush(QColor(50, 50, 50, 10)));
            m_chart->legend()->setPen(QPen(QColor(192, 192, 192, 192)));
            //![2]
            showLegendSpinbox();
            m_chart->legend()->setGeometry(QRectF(legend->geometry().x(),
                                                  legend->geometry().y(),
                                                  legend->geometry().width(),
                                                  legend->geometry().height()));
            QGraphicsScene *scene=m_chartView->scene();
            RectItem *item=new RectItem(legend,m_chartView);
            item->setRect(legend->geometry());
            item->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable | 
           QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope);
    
            scene->addItem(item);
            m_chart->legend()->update();```
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved