How to draw draggable custom legend enclosing all the legends items in qt charts
Unsolved
General and Desktop
-
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.
Attached is the code snippet in the qt legend example pertinent to making the legend position customlegend->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();```