How to make a ruler on the border of a QGraphicsView

前端 未结 2 1589
说谎
说谎 2021-01-23 12:02

I am working on a small .ui project and I am was trying to understand how to properly make a ruler on a QGraphicsView.

So when the use sees th

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-23 12:47

    On creation, scene->height() is zero by default. If ruler->setFixedHeight() unwittingly set the height of the ruler to 0, paintEvent for the ruler will not be called.

    void setScene(QGraphicsScene* scene)
        {
            QGraphicsView::setScene(scene);
            if (scene)
                ruler->setFixedHeight(scene->height());
        }
    

提交回复
热议问题