[Qt-interest] Handling software generated mouse events in Qt 3.3

Gleb "Crazy Sage" Igumnov crazy.sage at gmail.com
Thu Mar 12 07:15:36 CET 2009


Hello. I've got following problem:
I need to emulate mouse buttons from keyboard. Program consists of
main window and widget SCanvasView inherited from QCanvasView as main
widget. I've made following code in main window class to generate
mouse events:
void MainForm::keyPressEvent(QKeyEvent *event)
{
switch (event->key()) { /*there was code for cursor movement from keyboard*/
case Key_Space:
    	{QPoint p = this->mapFromGlobal(QCursor::pos());
	QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, p,
Qt::LeftButton, Qt::NoButton);
	QApplication::postEvent(this,e);
	event->accept();}
	break;
    default: event->ignore();
  }

}
void MainForm::keyReleaseEvent(QKeyEvent *event)
{
	 if(event->key() == Key_Space)
    	{QPoint p = this->mapFromGlobal(QCursor::pos());
	QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonRelease, p,
Qt::NoButton, Qt::NoButton);
	QApplication::postEvent(this,e);
        event->accept();}
	else{
	event->ignore();}}

But menus and toolbars do not respond to this event. Is there any way
to activate them in such way and how can I transfer this click events
to SCanvasView widget? And also there is contentsMousePressEvent,
contentsMouseReleaseEvent and contentsMouseMoveEvent members in
SCanvasView class, will they work with such software generated mouse
event, or I'll have to write additional mousePressEvent,
mouseReleaseEvent and mouseMoveEvent handlers?
-- 
With respect
Gleb "Crazy Sage" Igumnov                mailto:crazy.sage at gmail.com



More information about the Qt-interest-old mailing list