我有一个自定义QGraphicsScene,其中我有一个mouseMoveEvent(QGraphicsSceneMouseEvent *事件);
当我用鼠标悬停在场景上时,mouseMoveEvent会被正确触发。
但是当我按下鼠标按钮时,它就不再被触发了。
这就是我在主窗口中设置整个场景的方式:
scene = new NodeScene(this); -> My Custom QGraphicsScene class
scene->setSceneRect(QRectF(0, 0, 5000, 5000));
QHBoxLayout *layout = new QHBoxLayout;
view = new QGraphicsView(scene);
layout->addWidget(view);
view->setDragMode(QGraphicsView::RubberBandDrag);
view->setMouseTracking(true);
QWidget *widget = new QWidget;
widget->setLayout(layout);
setCentralWidget(widget);
scene->setCentralWidget(widget);
以下是我处理鼠标事件的代码(适用于Maya执行):
void NodeScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
MGlobal::displayInfo("Move");
QGraphicsScene::mouseMoveEvent(event);
}
void NodeScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
MGlobal::displayInfo("Press");
QGraphicsScene::mousePressEvent(event);
}
void NodeScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
MGlobal::displayInfo("Release");
QGraphicsScene::mouseReleaseEvent(event);
}
知道即使按下鼠标按钮我怎么能得到mouseMoveEvents?
答案 0 :(得分:1)
听起来你并没有实现所有的鼠标事件,只有mouseMoveEvent。
当覆盖鼠标事件时,您应该处理所有这些事件(移动,按下和释放事件)。
然后,您可以在按下事件中设置一个布尔值,以便在输入mouseMove事件时知道鼠标按钮是否按下。
答案 1 :(得分:0)
通过将我的代码与其他示例进行比较找到问题,这是由于 private function Connect()
{
//$this->settings = parse_ini_file("settings.ini.php");
try
{
# Read settings from INI file, set UTF8
$this->pdo = new PDO('mysql:host=localhost;dbname=xxxxx;charset=utf8', 'xxxxx', 'xxxxxx', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
# We can now log any exceptions on Fatal error.
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
# Disable emulation of prepared statements, use REAL prepared statements instead.
$this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
# Connection succeeded, set the boolean to true.
$this->bConnected = true;
}
catch (PDOException $e)
{
# Write into log
echo $this->ExceptionLog($e->getMessage());
die();
}
}
线。默认情况下,代码应该在QGraphicsView :: NoDrag上,并且只有在按下时才启用RubberBandDrag。