简体   繁体   English

Qt QGraphicsView或QLabel

[英]Qt QGraphicsView or QLabel

For a school project we need to make the game Puerto Rico in Qt. 对于学校项目,我们需要在Qt中制作游戏Puerto Rico I was looking at QGraphicsView to display the gameboard, but it seems that this was a lot harder than i tought and had a lot of functions i don't need. 我一直在看QGraphicsView来显示游戏板,但是这似乎比我更难,并且有很多我不需要的功能。 So now my question is it also possible to achieve something like a gameboard using only label and display pictures in them? 所以现在我的问题是,是否也可以仅使用标签并在其中显示图片来实现类似游戏板的功能?

You can display a picture using a QLabel widget using the pixmap property . 您可以使用pixmap属性使用QLabel小部件显示图片。 You can check the detailed information about QPixmap class and use links from it to learn which image class (QPixmap, QImage, QBitmap or QPicture) best fits your needs 您可以检查有关QPixmap类详细信息,并使用其链接来了解最适合您需求的图像类(QPixmap,QImage,QBitmap或QPicture)。

You can always just subclass QWidget and override the paintEvent(QPaintEvent *) method to draw the board using a QPainter. 您始终可以只是QWidget的子类,并重写paintEvent(QPaintEvent *)方法以使用QPainter绘制板。 (You'd probably also want to override the mousePressEvent(QMouseEvent *) and mouseReleaseEvent(QMouseEvent *) methods to react to the player's mouse inputs as well; and be sure to call update() whenever you want to schedule another call to paintEvent(QPaintEvent *) to redraw the game board) (您可能还想重写mousePressEvent(QMouseEvent *)mouseReleaseEvent(QMouseEvent *)方法,以对播放器的鼠标输入做出反应;并且一定要在要安排对paintEvent(QPaintEvent *)另一个调用时调用update() paintEvent(QPaintEvent *)paintEvent(QPaintEvent *)游戏板)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM