QGraphicsView hit test region on Linux
-
- Run the following piece of Qt code on Windows/Linux/Mac, and ensure that another program's window has already been opened and occupies the whole screen:
@#include <QApplication>
#include <QtGui/QDesktopWidget>
#include <QtGui/QGraphicsView>
#include <QtGui/QGraphicsScene>int main(int argc, char *argv[])
{
QApplication a(argc, argv);QGraphicsScene* const scene = new QGraphicsScene( &a ); // scene->setBackgroundBrush( Qt::transparent ); const QRect desktopAvailableGeometry = a.desktop()->availableGeometry(); const qreal percentage = 0.2; const qreal rectWidth = desktopAvailableGeometry.width() * percentage; const qreal rectHeight = desktopAvailableGeometry.height() * percentage; const QRectF rect( ( desktopAvailableGeometry.width() - rectWidth ) / 2.0, ( desktopAvailableGeometry.height() - rectHeight ) / 2.0, rectWidth, rectHeight ); scene->addRect( rect, QPen( Qt::black ), QBrush( Qt::yellow ) ); QGraphicsView view( scene ); view.setGeometry( desktopAvailableGeometry ); view.setAttribute( Qt::WA_TranslucentBackground ); view.setWindowFlags( Qt::FramelessWindowHint ); view.setStyleSheet( "* { background: transparent; border: none; }" ); // view.setBackgroundBrush( Qt::transparent ); view.show(); return a.exec();
}
@A rectangle pops-up in the center of the screen.
2) Click outside of the rectangle's area:
1. Windows: the rectangle is hidden in the background and a window of the underlying application (Windows Explorer for instance) becomes top one.
2. Linux: nothing happens. The application has occupied the whole desktop area and nothing is clickable except for OS's taskbar. This is the only operating system that causes this problem. The graphically transparent regions of the application are not mouse-transparent as well.
3. The same as on Windows.Please, recommend the best way to define the graphically transparent regions to be mouse transparent as well.
This happens only when using the Graphics-View Framework. If I create a simple QWidget and show it, the problem is not reproduced. - Run the following piece of Qt code on Windows/Linux/Mac, and ensure that another program's window has already been opened and occupies the whole screen:
-
The only solution available for the moment is the last post in "this":http://www.qtcentre.org/threads/28197-Click-through-window thread:
@#include <QX11Info>
#include <X11/Xlib.h>
#include <X11/extensions/shape.h>MyWidget::MyWidget() : QWidget()
{
QRegion region;
XShapeCombineRegion( QX11Info::display(), winId(), ShapeInput, 0, 0, region.handle(), ShapeSet );
}@The problem with this code is that if the user interface is dynamic - created from movable QGraphicsItem-based controls, one should periodically do the following:
- create a ARGB32 QImage and paint the whole UI there
- create a mask out of the QImage where the black color indicates the opaque and semi-transparent areas and the white color - the fully transparent ones
- convert the mask it to QPixmap
- create a QRegion out of the QPixmap mask
The aforementioned procedure adds significant overhead to the Linux version of the application.
Is there any Qt integrated way to perform this mouse input transparency?