QGraphicsView::fitInView()似乎忽略了滾動條的存在,顯然它們是重疊的。 (它也使用硬編碼的2像素邊距。)Qt QGraphicsScene不適合使用滾動條的InView()
有一個相關的錯誤報告(https://bugreports.qt-project.org/browse/QTBUG-1047)指出,調用fitInView()兩次可以解決問題。
在我的情況下,它沒有。只有手動觸發兩次才適合滾動條。這是行不通的:
void myGraphicsView::mousePressEvent(QMouseEvent *event) {
if(event->button() == Qt::LeftButton) {
QGraphicsItem* clicked = scene()->itemAt(mapToScene(event->pos()));
qDebug() << clicked << clicked->boundingRect();
fitInView(clicked, Qt::KeepAspectRatio);
fitInView(clicked, Qt::KeepAspectRatio); // doesn't work for me
QGraphicsView::mousePressEvent(event);
return;
}
}
是否有另一種解決方法?
的Qt 4.8.1與MSVC2010