我想在qt中单击(左或右)小部件时显示一条消息

i want to display a message when i click(left or right) on widget in qt

本文关键字:小部 显示 消息 一条 qt 单击      更新时间:2023-10-16

此代码适用于VLC媒体播放器。如果我在全屏中移动鼠标,就会显示消息和x,y坐标。我想在全屏上单击(左或右)时显示一条消息。我该怎么做?我正在使用Qt。

void FullscreenControllerWidget::mouseChanged( vout_thread_t *p_vout, int i_mousex, int i_mousey )
{
    bool b_toShow;
    /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
    qDebug() << "mouse moved"; //ajay
    b_toShow = false;
    if ((i_mouse_last_move_x == -1 || i_mouse_last_move_y == -1) ||
        (abs( i_mouse_last_move_x - i_mousex ) > 2 ||
         abs( i_mouse_last_move_y - i_mousey ) > 2 ))
    {
        i_mouse_last_move_x = i_mousex;
        i_mouse_last_move_y = i_mousey;
        qDebug() << "mouse move changed x:" << i_mouse_last_move_x; // ajay
        qDebug() << "mouse move changed y:" << i_mouse_last_move_y; // ajay
        b_toShow = true;
    }
    if (b_toShow)
    {
        /* Show event */
        IMEvent *eShow = new IMEvent(FullscreenControlShow_Type, 0);
        QApplication::postEvent(this, eShow);
        /* Plan hide event */
        IMEvent *eHide = new IMEvent(FullscreenControlPlanHide_Type, 0);
        QApplication::postEvent(this, eHide);
    }
}

鼠标点击有一个特殊事件。

  • http://developer.qt.nokia.com/doc/qt-4.8/qwidget.html#mousePressEvent
  • http://developer.qt.nokia.com/doc/qt-4.8/qwidget.html#mouseReleaseEvent

你试过执行这些吗?顺便说一下,mouseChanged是特定于vlc的。