QGraphicsView and QGraphicsItem: don´t scale item when scaling the view rect

后端 未结 5 1626
既然无缘
既然无缘 2021-02-04 13:46

I am using Qt´s QGraphicsView - and QGraphicsItem-subclasses. is there a way to not scale the graphical representation of the item in the view when the

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 14:12

    I found that if I derive a new class and reimpliment the paint function I can do

    void MyDerivedQGraphicsItem::paint(QPainter *painter, 
                                       const QStyleOptionGraphicsItem *option, 
                                       QWidget *widget)
    {
      double scaleValue = scale();
      double scaleX = painter->transform().m11();
      setScale(scaleValue / scaleX);
      QGraphicsSvgItem::paint(painter,option,widget);
    }
    

    This is the best way of doing it that I have found so far, but I am still tinkering around.

提交回复
热议问题