Qt5 C++ QGraphicsView: Images don't fit view frame

后端 未结 4 2094
挽巷
挽巷 2020-12-18 21:31

I\'m working on program which shows user some picture that is selected by him. But there is a problem because I would like to fit this picture in QGraphicsView\'s frame and

4条回答
  •  囚心锁ツ
    2020-12-18 21:55

    Solution for my question is showEvent() for Dialog. This means that you can't call fitInView() before the form is showed, so you have to create showEvent() for dialog and the picture will be fitted into QGraphics View's frame.

    And example code which you have to add into dialog's code:

    void YourClass::showEvent(QShowEvent *) {
        ui->graphicsView->fitInView(scn->sceneRect(),Qt::KeepAspectRatio);
    }
    

提交回复
热议问题