How to trigger a click on known coordinates of the screen?

244 Views Asked by At

Consider I have two windows: window1 and window2 like below

------------------------------
| x | This is the window1    |
|----------------------------|
|                            |
|    This window contains    |
|   a webview that has       |
|   transparent background. -|----------------|
|           | x |            | This is window2|
|            - - - - - - - --|----------------|
|           |If I click HERE |                |
------------------------------                |
            | I want to activate window2.     |
            |                                 |
            |                                 |
            |                                 |
            -----------------------------------

window1 loads a HTML file into a QWebView and there is a transparent area like described here.

Now the problem is that when I click on the transparent area the window that is under the window1 (in this case window2) is not activated. That's normal, because there is a HTML document with a transparent background.

I think that the correct way would be to make a function in C++ that would simulate a click on known coordinates under the activated window.

How can I do this in Qt?

1

There are 1 best solutions below

1
Kirell On

I guess you can reimplement the virtual QWidget function:

void QWidget::mousePressEvent( QMouseEvent * event )

And specify the "clickable rectangle" :

void MyWebView::mousePressEvent( QMouseEvent * event ) {
   // Set this a class variable
   QRect clickableArea = QRect( int x, int y, int width, int height);
   if( clickableArea->contains(event->pos()) ) {
       // Activate window2
   }
}