1
A
回答
1
最簡單的方法是添加一個不可見的QGraphicsRectItem
作爲第一項。
然後添加其他項目作爲第一個項目的子項目。
第一項的中心是協調中心。
QGraphicsScene *scene = new QGraphicsScene(widget.graphicsView);
// ....
QGraphicsRectItem *frame = scene->addRect(-100,-100,100,100);
frame->setPen(Qt::NoPen);
// ....
// Add new items as children of frame
// Align them relative to their parent
^
|
|
-100,100 | 100,100
+-----------------------------+
| | |
| | |
| | |
| | |
| | |
| | |
| | |
---------------------------+------------------------>
| | |
| | |
| | |
| | |
| | |
| | |
| | |
+-----------------------------+
-100,100 | 100,-100
|
,讓其獲取窗口大小,覆蓋這些方法:
class MainForm : public QMainWindow
{
//...
QGraphicsScene *scene; // Move it here
QGraphicsRectItem *frame; // Move it here
protected:
virtual void resizeEvent(QResizeEvent * event);
virtual bool event(QEvent * event);
virtual void resizeAction();
//...
};
void MainForm::resizeAction()
{
QRectF rect(field->rect());
widget.graphicsView->setSceneRect(rect);
widget.graphicsView->fitInView(rect, Qt::KeepAspectRatio);
}
void MainForm::resizeEvent(QResizeEvent * event)
{
resizeAction();
QMainWindow::resizeEvent(event);
}
bool MainForm::event(QEvent * event)
{
if (event->type() == QEvent::Show)
resizeAction();
return QMainWindow::event(event);
}
0
Scene_item.setSceneRect(x0,y0,x1,y1);
相關問題
- 1. Qt場景項目組邊界矩形沒有跟隨旋轉
- 2. 在PyQt中更新Qt場景圖
- 3. 如何在文件中保存Qt圖形場景項並再次打開它?
- 4. 在一個場景中移動一個項目Qt
- 5. 爲什麼第一個添加的項目總是出現在Qt的圖形場景/視圖的中心?
- 6. Qt在移動時在場景位置拖動項目
- 7. QT圖形場景/視圖 - 用鼠標移動
- 8. QT識別場景中的選定項目
- 9. JavaFX場景調整大小
- 10. 如何更新Qt Widgets項目中的圖形視圖(Qt Creator)
- 11. Qt在現場/視圖的中心添加項目
- 12. Qt的圖形場景鼠標事件傳播
- 13. Qt - 拖放 - 自定義圖形場景 - 事件錯誤
- 14. 調整Qt中
- 15. 調整SpriteKit場景的大小
- 16. 如何導出整個Unity項目與所有場景?
- 17. 背景圖像整形
- 18. 如何調整qt佈局中的項目大小?
- 19. 從線程更新JavaFX場景圖形
- 20. Qt 5項目可以調用Qt 4項目嗎?
- 21. 在DirectX中調整場景的亮度/對比度/伽馬值?
- 22. 優化項目的場景對象
- 23. 在matplotlib中自動調整圖形
- 24. 在Qt圖形視圖中獲取恆定大小項目的邊界框
- 25. Qt GraphicsScene繪圖項目
- 26. 調整itemview的項目視圖
- 27. 調試JBehave場景
- 28. 調整幾何圖形/幾何圖形
- 29. 用QGraphics場景顯示圖像場景
- 30. Qt - QGraphics(異形)的選擇項目
我想,當你調整窗口的大小有圖形的項目也跟着左邊。如果我調整窗口大小,它們會失去初始對齊並最終出現在中心。 – user1845360 2013-04-09 11:12:12
@ user1845360:我更新了我的答案。 – deepmax 2013-04-09 11:16:47
這裏的問題是,隨着窗口大小的增加,我的圖形項目被放大。 – user1845360 2013-04-09 12:47:41