Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
Graphics 系列介紹
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
QGraphics QGraphics 是 Qt 中的一種框架,可以管理大量的自製的圖形單元,支援以下功能:
我們可以使用多重繼承搭配一系列 QGraphics 與其他的 class 組合出功能複雜的視窗程式與遊戲。
用 QGraphics 所設計的遊戲範例:
西洋棋
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
小精靈
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
相關模型 基本的 QGraphics class 如下:
QGraphicsView - 觀看視角
QGraphicsScene - 場景
QGraphicsItem - 物件主體
QGraphicsRectItem
QGraphicsPixmapItem
QGraphicsObject
QGraphicsItem
Image Not Showing
Possible Reasons
The image was uploaded to a note which you don't have access to The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
QGraphicsView 視角,支援視角縮放等等功能
需要加入 <QGraphicsView>
有兩種使用的方法:
直接在 mainwindow 中建立 QGraphicsView
使用 QGraphicsView 作為視窗主體
QGraphicsView * view = new QGraphicsView ( ) ;
view-> setScene ( scene) ;
view-> setFixedSize ( 500 , 400 ) ;
view-> setHorizontalScrollBarPolicy ( Qt:: ScrollBarAlwaysOff)
view-> setVerticalScrollBarPolicy ( Qt:: ScrollBarAlwaysOff)
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
QGraphicsScene 場景,將物件與圖片擺放的位置,定義在 <QGraphicsScene>
中
QGraphicsScene * scene = new QGraphicsScene ( ) ;
scene-> setSceneRect ( 0 , 0 , 500 , 400 ) ;
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
QGraphicsItem 基本的 QGraphics 物件 (定義在 <QGraphicsItem>
),接下來要介紹的 QGraphicsRectItem, QGraphicsPixmapItem, QGraphicsTextItem 全部都是從它延伸擴充而成
QGraphicsItem * item = new QGraphicsItem ( ) ;
item-> setPos ( x, y) ;
item-> setX ( x) ;
item-> setY ( y) ;
double x = item-> x ( ) ;
double y = item-> y ( ) ;
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
QGrphicsRectItem 就是一個正方形,定義在 <QGraphicsRectItem>
QGraphicsRectItem * rect = new QGraphicsRectItem ( ) ;
rect-> setRect ( 0 , 0 , 50 , 50 ) ;
rect-> setPos ( 100 , 200 ) ;
scene-> addItem ( rect) ;
QPen pen;
pen. setColor ( color) ;
pen. setWidth ( width) ;
rect-> setPen ( pen) ;
rect-> setBrush ( Qt:: red) ;
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
QGraphicsPixmapItem 可以使用圖片的物件,記得引用 <QGraphicsPixmapItem>
。
QGraphicsPixmapItem * pic = new QGraphicsPixmapItem ( ) ;
pic-> setPixmap ( QPixmap ( path_to_your_picture) ) ;
scene-> addItem ( pic) ;
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
QGraphicsTextItem QGraphics 的文字物件,定義在 <QGraphicsTextItem>
QGraphicsTextItem * text = new QGraphicsTextItem ( ) ;
text-> setFont ( QFont ( font_family, font_size) ) ;
text-> setPlainText ( "Hello World" ) ;
text-> setDefaultColor ( Qt:: red) ;
scene-> addItem ( text) ;
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
QGraphicsItemGroup 將多個物件包裝在一起,類似 Word 與 PowerPoint 群組化物件的功能,使用前記得在 header 加入 <QGraphicsItemGroup>
。
Image Not Showing
Possible Reasons
The image was uploaded to a note which you don't have access to The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
The image was uploaded to a note which you don't have access to The note which the image was originally uploaded to has been deleted
Learn More →
QGraphicsItemGroup * group = new QGraphicsItemGroup ( ) ;
group-> addToGroup ( rect) ;
group-> addToGroup ( pic) ;
scene-> addItem ( group) ;
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
QGraphicsItem::collidesWithItem 可以用來判斷兩個物件有沒有碰撞的函式
bool isCollided = item1-> collidesWithItem ( item2, mode) ;
Qt 提供下列等碰撞的模式供我們使用 (詳細的描述可以參考 官方文件 )
Qt::ContainsItemShape
: 判斷物件是否包覆
Qt::IntersectsItemShape
: 判斷物件是否相交、包覆(預設)
Qt::ContainsItemBoundingRect
: 判斷最小外接矩形是否包覆
Qt::IntersectsItemBoundingRect
: 判斷最小外接矩形是否相交、包覆
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
設計思維
思考要建立的物件需要使用到哪些功能
決定使用哪個 class 作為模板,疊加出你所需要的功能
ex:以 QGraphicsPixmapItem 作為基底,使用 QTimer 做成動畫等等
利用 constructor 做初始的設定
ex:載入圖片,設定起始位置,一開始要顯示還是隱藏等等
使用成員函式定義行為
加入 QGraphicsScene 中並依照用途進行操作
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
餐餐自由配
QGraphicsItem + QKeyEvent
QGraphicsItem + QTimer + QObject
QGraphicsItem + QPropertyAnimation
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
參考影片