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

后端 未结 4 2120
挽巷
挽巷 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

    You should handle resize event, I guess it's the way it's meant to be played:

    bool YourDialog::eventFilter(QObject *obj, QEvent *event)
    {
            if (event->type() == QEvent::Show){
                ui->conceptView->fitInView(conceptScene->sceneRect(), Qt::KeepAspectRatio);
            }
    
            if (event->type() == QEvent::Resize){
                ui->conceptView->fitInView(conceptScene->sceneRect(), Qt::KeepAspectRatio);
            }
    }
    

提交回复
热议问题