简体   繁体   English

Qt 5.5-触摸屏事件仅在初始(第一个)窗口中有效

[英]Qt 5.5 - touchscreen-events only working in initial (first) window

I've set up a basic Qt-Widgets-Application (Qt 5.5 community) with a simple QWidget "MainWindow" and an additinal QWidget "SettingsScreen". 我已经建立了一个基本的Qt-Widgets-Application(Qt 5.5社区),它带有一个简单的QWidget“ MainWindow”和一个附加的QWidget“ SettingsScreen”。

Within the "MainWindow", touchscreen-events (handled by OS) are working as expected, but after opening the "SettingsScreen" all touch-events are executed on the desktop until I close the "SettingsScreen" using mouse or keyboard. 在“ MainWindow”中,触摸屏事件(由OS处理)按预期方式工作,但是在打开“ SettingsScreen”后,所有触摸事件都在桌面上执行,直到我使用鼠标或键盘关闭“ SettingsScreen”。

Environment: 环境:

  • Ubuntu Studio 14.04.03 Ubuntu Studio 14.04.03
  • Qt 5.5 Open Source Edition Qt 5.5开源版

mainwindow.h 主窗口

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QWidget>
#include <settingsscreen.h>

namespace Ui {
class MainWindow;
}

class MainWindow : public QWidget
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:

    void on_btnExit_clicked();

    void on_btnSettings_clicked();

private:
    Ui::MainWindow *ui;
    SettingsScreen *wSettingsScreen;
};

#endif // MAINWINDOW_H

mainwindow.cpp 主窗口

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "settingsscreen.h"
#include "ui_settingsscreen.h"

MainWindow::MainWindow(QWidget *parent) : QWidget(parent),
ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_btnExit_clicked()
{
    this->close();
}

void MainWindow::on_btnSettings_clicked()
{
    wSettingsScreen = new SettingsScreen(parentWidget());
    wSettingsScreen->show();
}

settingsscreen.h settingsscreen.h

#ifndef SETTINGSSCREEN_H
#define SETTINGSSCREEN_H

#include <QWidget>

namespace Ui {
class SettingsScreen;
}

class SettingsScreen : public QWidget
{
    Q_OBJECT

public:
    explicit SettingsScreen(QWidget *parent = 0);
    ~SettingsScreen();

private slots:
    void on_pushButton_clicked();

    void on_btnBack_clicked();

private:
    Ui::SettingsScreen *ui;
};

#endif // SETTINGSSCREEN_H

settingsscreen.cpp settingsscreen.cpp

#include "settingsscreen.h"
#include "ui_settingsscreen.h"

SettingsScreen::SettingsScreen(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SettingsScreen)
{
    ui->setupUi(this);
}

SettingsScreen::~SettingsScreen()
{
    delete ui;
}

void SettingsScreen::on_btnBack_clicked()
{
    this->close();
}

I've just started developing with Qt, so please forgive me if I'm missing something essential :) 我刚刚开始使用Qt进行开发,所以如果我缺少一些重要的东西,请原谅我:)

Any help would by highly appreciated!! 任何帮助将不胜感激!

Thank you in advance! 先感谢您!

Actually the thing is QMainwindow or any base Widget of your application is able to properly synthesize the Unhandled touch screen events to Mouse events. 实际上,问题是QMainwindow或应用程序的任何基本Widget都能正确地将未处理的触摸屏事件合成为Mouse事件。 So whenever you are creating a dialog/widget, make sure to set Mainwindow as there parent and in the constructor of the child widget use setParent(parent). 因此,每当创建对话框/小部件时,请确保将Mainwindow设置为父级,在子小部件的构造函数中使用setParent(parent)。 Even I was facing this kind of Issue and this worked for me. 甚至我也面临这种问题,这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM