【发布时间】:2016-06-01 16:50:22
【问题描述】:
我遇到了 QMouseEvent 的问题:
void Gioco::gioco_G1()
{
QMouseEvent *mouse = new QMouseEvent;
bool stato = false;
do
{
if (mouse->KeyPress() == Qt::MouseButton::LeftButton) {
qDebug()<<"entra nell'if";
if (img_mano1G1 -> isUnderMouse()) {giocata_G1 = manoG1[0]; stato = true;}
else if (img_mano2G1 -> isUnderMouse()) {giocata_G1 = manoG1[1]; stato = true;}
else if (img_mano3G1 -> isUnderMouse()) {giocata_G1 = manoG1[2]; stato = true;}
}
} while (stato == false); //repeat until I enter an if
}
我创建了一个场景,并在场景中插入了一些 QGraphicsPixmapItem。 现在我想在单击指定的 QGraphicsPixmapItem 时输入“if”。
例如,当我点击 img_manoG1 时,我想在第一个“if”中输入
如何让程序停止并等待鼠标输入?
TI 是 Qt 新手,这是我第一次使用对象,所以我犯了很多逻辑错误,所以使用 QStateMachine 是个大问题...
这是唯一的方法吗?我试着解释我的程序:
我想创建一个纸牌游戏,在以前的版本中,我使用了一个带有以下命令序列的旧图形库:
-> print cards on the scene
-> wait for a mouse input (with a do-while)
-> if(isMouseClick(WM_LBUTTONDOWN))
-> if(mouse position is on the first card)
-> select that card. So i wish to do the same thing with QGraphics.
这样我告诉程序:
-> print cards
-> wait for a mouse event
-> print the card that I've selected with that event.
现在我想改变程序图形,我已经介绍了 QGraphics。 我已经创建了一个场景并在上面打印了所有对象“卡片”,所以现在我想告诉程序:
-> print the object and wait the mouse input
-> if a card is to selected with the left clik
-> print that card in scene, wait 1/2 second and go ahead with the program
问题是我使用了 for 1 到 20(我必须在一场比赛中运行 20 次)。
我尝试使用随机 G1 和 COM 播放来启动该程序,但应用程序冻结,直到最后一次执行 for 并且我在现场仅打印卡的最后配置。
这就是原因,因为之前我说过我希望程序停止......
没有 QStateMachine 可以吗? 简单地告诉他:“暂停”,打印这个情况,等待鼠标继续?
【问题讨论】:
-
你提供的例子不是它应该的样子。见那里:codeprogress.com/cpp/libraries/qt/…,也许那里:youtube.com/watch?v=hO0u_pdTJKA
标签: qt qevent qmouseevent