c++ - Qt Creator,C++,鼠标悬停功能

标签 c++ qt qt-creator

我想在将鼠标移到椭圆上时更改椭圆的颜色。 但是我还没有从 Qt Creator 的引用和自动完成中找到任何东西。

你们知道怎么做吗?

我的一些代码:

void DrawingWidget::paintEvent(QPaintEvent *event) {
    QPainter painter(this);
    painter.fillRect(event->rect(), Qt::white);

    for(int i = 0; i < pointList.size(); i++) {
        if (pointList[i].x() >= 0 && pointList[i].y() >= 0)
            painter.drawEllipse(pointList[i], 10, 10);
    }
    painter.drawLines(lineList);
    m_mainWindow->updateCount();
}

鼠标按下事件处理程序:

void DrawingWidget::mousePressEvent(QMouseEvent *event) {
    if (event->button() == Qt::LeftButton
        && event->buttons() == Qt::LeftButton) {
        // DO STUFFF
    }
}

鼠标移动事件处理程序:

void DrawingWidget::mouseMoveEvent(QMouseEvent *event) {
    if (m_mainWindow->getSelectedTool() == MainWindow::moveVertexTool) {
        m_x = event->x();
        m_y = event->y();
        if (isPointNear(m_x, m_y)) {
            //STUFF
        }
            update();
        }
    }
}

现在我只需要一个鼠标 OVER 事件(处理程序)。

最佳答案

我想你要找的是enterleave事件。

关于c++ - Qt Creator,C++,鼠标悬停功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5614635/

相关文章:

c++ - 不使用数学/按位运算符查找偶数/奇数

macos - MacOS QT 中的错误消息 "OpenCV: not authorized to capture video (status 0)"

c++ - 如何正确重写虚方法来添加功能?

c++ - 没有警告输出时显示警告图标(Qt Creator IDE)

c++ - 具有运算符重载的函数模板

c++ - Linux 系统调用 getname info 返回 EAI_AGAIN

c++ - 无法使用 cmath 编译代码

c++ - Qt 测试 : error symbol(s) not found when instantiating object in test project

c++ - 没有 QAction 的匹配信号,没有 "go to slot"菜单项

c++ - 使用 mingw-w64 时找不到或未正确包含 float.h