QT鼠标键盘事件

QT文章列表

鼠标-按下

void mousePressEvent(QMouseEvent *event);
void DrawBaseWidget::mousePressEvent(QMouseEvent *event)
{
	// 如果是鼠标左键按下
	if (event->button() == Qt::LeftButton)
	{
		m_bLButtonDown = true;
		m_prePoint = event->pos();
		//qDebug() << "mousePressEvent() Qt::LeftButton m_bLButtonDown = true";
	}
}

鼠标-滚轮

void wheelEvent(QWheelEvent*event);//滚轮

void MyStrategyQUI::wheelEvent(QWheelEvent * event)
{
	static int i = 0;
	//如果滚轮往上滚
	if (event->delta() > 0)
	{
		std::cout << "MyStrategyQUI::wheelEvent event->delta() > 0 "<<++i << std::endl;
	}
	//如果滚轮往下滚
	else
	{
		std::cout << "MyStrategyQUI::wheelEvent event->delta() <  " << ++i << std::endl;
	}
}

键盘-按下

void keyPressEvent(QKeyEvent *event);   //键盘按下事件
void MyStrategyQUI::keyPressEvent(QKeyEvent * event)
{
	if (event->key() == Qt::Key_Control)
	{
		m_ctrlButtonDown = true;
		std::cout << "MyStrategyQUI::keyPressEvent event->key() == Qt::Key_Control " << std::endl;
	}
}

 键盘-松开(抬起)

void keyReleaseEvent(QKeyEvent *event); //键盘松开事件
void MyStrategyQUI::keyReleaseEvent(QKeyEvent * event)
{
	if (event->key() == Qt::Key_Control)
	{
		m_ctrlButtonDown = false;
		std::cout << "MyStrategyQUI::keyReleaseEvent event->key() == Qt::Key_Control " << std::endl;
	}
}

 

你可能感兴趣的:(QT)