I need to write an application that parses the pixel of the screen when I click on any position, OpenSuse OS.
There is an extended root window class:
class DesktopMouseGrabber : public QDesktopWidget { public: QMainWindow* main_window; DesktopMouseGrabber(QMainWindow *window_) : QDesktopWidget(), main_window(window_) {} void mousePressEvent(QMouseEvent *e); }; void DesktopMouseGrabber::mousePressEvent(QMouseEvent *e) { // ΡΠΎΠ±ΡΡΠΈΠ΅ ΠΊΠ»ΠΈΠΊΠ° ΠΏΠΎ Π²ΠΈΠ΄ΠΆΠ΅ΡΡ QApplication::postEvent(main_window, e); } And the window:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); start = false; desktopWidget = QApplication::desktop(); m_grabber = static_cast<DesktopMouseGrabber*>(desktopWidget); // ΡΠΈΠΏ m_grabber DesktopMouseGrabber* m_grabber->main_window = static_cast<MainWindow* (this); // ΡΠΈΠΏ m_grabber->main_window - QMainWindow* m = this; connect( ui->selectButton, SIGNAL(clicked()), this, SLOT(onButtonSelectClick()) ); connect( ui->startButton, SIGNAL(clicked()), this, SLOT(onButtonStartClick ()) ); } // ΠΠ°ΠΆΠΈΠΌΠ°Π΅ΠΌ Π½Π° ΠΊΠ½ΠΎΠΏΠΊΡ, ΡΠ²ΠΎΡΠ°ΡΠΈΠ²Π°Π΅ΠΌ ΠΎΠΊΠ½ΠΎ, Π΄Π΅Π»Π°Π΅ΠΌ ΡΡΠΎΠ±Ρ Π²ΠΈΠ΄ΠΆΠ΅Ρ ΠΊΠΎΡΠ½Π΅Π²ΠΎΠ³ΠΎ ΠΎΠΊΠ½Π° Π·Π°Ρ
Π²Π°ΡΠΈΠ» ΠΌΡΡΡ void MainWindow::onButtonSelectClick() { showMinimized(); m_grabber->grabMouse(); } void MainWindow::customEvent(QEvent *e) { // ΠΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ ΡΠΎΠ±ΡΡΠΈΡ ΠΊΠ»ΠΈΠΊΠ° ΠΏΠΎ ΠΊΠΎΡΠ½Π΅Π²ΠΎΠΌΡ ΠΎΠΊΠ½Ρ QMouseEvent* event = static_cast<QMouseEvent*>(e); m_grabber->releaseMouse(); this->show(); } } Problem: when you click the mouse on the desktop, nothing happens, the mouse is not released, the window does not open, what am I doing wrong?
Are there any alternative methods for solving the issue?