Originally Posted by
yogeshgokul
You just need to calculate the scaling factor depending upon the current size of gv.
Pass that scaling factor in scale function of gv in resizeEvent.
Thanks yogeshgokul i will do some simple examples to figure it out.
It's different because in my app i have different setup.
here i go:
//Program entry point: instancing object of RuletV1 class
int main(int argc, char *argv[])
{
RuletV1 w;
w.show();
return a.exec();
}
//Program entry point: instancing object of RuletV1 class
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
RuletV1 w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
//RuletV1.cpp
RuletV1
::RuletV1(QWidget *parent, Qt
::WFlags flags
)
ui.setupUi(this);
ui.graphicsView->setScene(scena);
m_elipsa = new CircleItem();
scena->addItem(m_elipsa);
} RuletV1::~RuletV1(){}
//RuletV1.cpp
RuletV1::RuletV1(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags) {
ui.setupUi(this);
QGraphicsScene *scena = new QGraphicsScene();
ui.graphicsView->setScene(scena);
m_elipsa = new CircleItem();
scena->addItem(m_elipsa);
} RuletV1::~RuletV1(){}
To copy to clipboard, switch view to plain text mode
//CirceItem.cpp
//destructor
CircleItem::~CircleItem() {}
QRectF CircleItem
::boundingRect() const { return QRectF(0,
0,
100,
100);
}
{
painter
->setRenderHint
(QPainter::Antialiasing);
painter->drawLine(0,50, 100, 50);
painter->drawLine(50, 0, 50, 100);
painter->drawEllipse(0, 0, 100, 100);
}
//CirceItem.cpp
CircleItem::CircleItem(QGraphicsItem *parent)
: QGraphicsItem(parent) {}
//destructor
CircleItem::~CircleItem() {}
QRectF CircleItem::boundingRect() const { return QRectF(0,0,100,100); }
void CircleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
painter->setRenderHint(QPainter::Antialiasing);
painter->drawLine(0,50, 100, 50);
painter->drawLine(50, 0, 50, 100);
painter->drawEllipse(0, 0, 100, 100);
}
To copy to clipboard, switch view to plain text mode
If i understand then you have also GraphicsView but not like me, you make yourself a class that inherits QGraphicsView, you named it MyView. And in that class you override a method called resizeEvent.
The rest i understand...i need to study that resizeEvent method and how to calculate scaling. Thx
Bookmarks