[SOLVED]QGraphicsScene::mousePressEvent: Since Qt5.3 the shortest response time is about 190ms after last press event!



  • Hi,

    I'm working on a drum computer application and use QGraphicsView/Scene to draw all
    items. One of the main responsibilities are: By pressing of pads the ability to make
    a beat (let say on a android pad or on a PC by mouse clicking).

    For example folowing beat:
    @
    Basedrum: X.......X.X.....
    Snaredrum: ....X.......X...
    @

    Since Qt5.3 it's no more posible to do this because of some delays (on Win7, Ubuntu 14..., Android 4....).

    I made a test with a minimal implementation, additionaly test it with QWidget Button too.

    I execute the app and try click fast as i can:

    Timings on Qt 5.3.1 --> shortest response time ~190ms

    Time: 48,593 -- Scene::mousePressEvent
    Time: 48,785 -- Scene::mousePressEvent
    Time: 48,985 -- Scene::mousePressEvent
    Time: 49,169 -- Scene::mousePressEvent
    Time: 49,361 -- Scene::mousePressEvent
    Time: 35,544 -- MainWindow::on_pushButton_pressed
    Time: 35,648 -- MainWindow::on_pushButton_pressed
    Time: 35,752 -- MainWindow::on_pushButton_pressed
    Time: 35,856 -- MainWindow::on_pushButton_pressed
    Time: 35,936 -- MainWindow::on_pushButton_pressed

    Timings on Qt 5.2.1 --> shortest response time ~90ms:
    Time: 20,626 -- Scene::mousePressEvent
    Time: 20,714 -- Scene::mousePressEvent
    Time: 20,802 -- Scene::mousePressEvent
    Time: 20,897 -- Scene::mousePressEvent
    Time: 20,985 -- Scene::mousePressEvent
    Time: 05,537 -- MainWindow::on_pushButton_pressed
    Time: 05,633 -- MainWindow::on_pushButton_pressed
    Time: 05,721 -- MainWindow::on_pushButton_pressed
    Time: 05,825 -- MainWindow::on_pushButton_pressed
    Time: 05,913 -- MainWindow::on_pushButton_pressed

    @main.cpp

    #include "mainwindow.h"
    #include <QApplication>
    int main(int argc, char *argv[]) {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
    }

    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include <QMainWindow>

    namespace Ui { class MainWindow; }
    class MainWindow : public QMainWindow {
    Q_OBJECT
    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    private slots:
    void on_pushButton_pressed();
    private:
    Ui::MainWindow *ui;
    };
    #endif // MAINWINDOW_H

    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QGraphicsView>
    #include <QGraphicsScene>
    #include <QTime>
    #include <iostream>
    #include <iomanip>

    void debug(const QString& cName, const QString& fName) {
    QTime time = QTime::currentTime();
    std::cout << "Time: "
    << std::setw(2)<< std::right << std::setfill('0') << time.second()
    << ","
    << std::setw(3)<< std::left << time.msec()
    << " -- " << cName.toStdString()
    << "::" << fName.toStdString() << std::endl;
    }
    class Scene : public QGraphicsScene {
    protected:
    virtual void mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent) {
    Q_UNUSED(mouseEvent);
    debug("Scene", "mousePressEvent");
    }
    };
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow) {
    ui->setupUi(this);
    auto rect = ui->graphicsView->geometry();
    rect.adjust(0, 0, -4, -4);
    ui->graphicsView->setSceneRect(rect);
    ui->graphicsView->setScene(new Scene());
    }
    MainWindow::~MainWindow() {
    delete ui;
    }
    void MainWindow::on_pushButton_pressed() {
    debug("MainWindow", "on_pushButton_pressed");
    }

    mainwindow.ui

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>MainWindow</class>
    <widget class="QMainWindow" name="MainWindow">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>196</width>
    <height>96</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>MainWindow</string>
    </property>
    <widget class="QWidget" name="centralWidget">
    <widget class="QPushButton" name="pushButton">
    <property name="geometry">
    <rect>
    <x>10</x>
    <y>10</y>
    <width>75</width>
    <height>71</height>
    </rect>
    </property>
    <property name="text">
    <string>PushButton</string>
    </property>
    </widget>
    <widget class="QGraphicsView" name="graphicsView">
    <property name="geometry">
    <rect>
    <x>110</x>
    <y>10</y>
    <width>71</width>
    <height>71</height>
    </rect>
    </property>
    </widget>
    </widget>
    </widget>
    <layoutdefault spacing="6" margin="11"/>
    <resources/>
    <connections/>
    </ui>

    TestQTGUIStuff.pro

    QT += core gui
    TARGET = TestQTGUIStuff
    TEMPLATE = app
    CONFIG += c++11
    SOURCES += main.cpp
    mainwindow.cpp
    HEADERS += mainwindow.h
    FORMS += mainwindow.ui

    @

    Is there something which i forgot to set up or do not correctly program?
    What changes with Qt5.3 that this behaviour happens?

    Thank you in advance!


  • Lifetime Qt Champion

    Hi,

    Pretty strange indeed,

    Can you test with the 5.4 beta ?



  • qt-opensource-windows-x86-mingw482_opengl-5.4.0-beta_2014-10-15_12-07-18-43.exe

    Time: 48,222 -- Scene::mousePressEvent
    Time: 48,414 -- Scene::mousePressEvent
    Time: 48,589 -- Scene::mousePressEvent
    Time: 48,757 -- Scene::mousePressEvent
    Time: 48,950 -- Scene::mousePressEvent
    Time: 49,133 -- Scene::mousePressEvent
    Time: 49,309 -- Scene::mousePressEvent



  • 5.4 seems to be the same, still 190ms.
    I compared qtbase\src\widgets\graphicsview 5.2.1 and 5.3.2 code and could not find any indications. Must be somewhere deeper....
    pushButton still works fast.



  • And the same with MSVS2010 (~190ms):

    Time: 12,165 -- Scene::mousePressEvent
    Time: 12,357 -- Scene::mousePressEvent
    Time: 12,549 -- Scene::mousePressEvent
    Time: 12,749 -- Scene::mousePressEvent
    Time: 12,933 -- Scene::mousePressEvent
    Time: 13,125 -- Scene::mousePressEvent
    Time: 13,309 -- Scene::mousePressEvent
    Time: 13,509 -- Scene::mousePressEvent

    qt-opensource-windows-x86-msvc2010_opengl-5.4.0-beta_2014-10-15_12-07-18-43.exe



  • [SOLVED]

    i compare the
    "void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e)" function of qt5.2.1 and qt5.4

    Because of "Qt QTBUG-25831Event behavior for QEvent::MouseButtonDblClick changed since Qt 4"

    The solution is: override also QGraphicsScene::mouseDoubleClickEvent and use it as a normal mousePressEvent.

    @
    class Scene : public QGraphicsScene
    {
    protected:
    virtual void mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent)
    {
    Q_UNUSED(mouseEvent);
    debug("Scene", "mousePressEvent");
    }
    virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* mouseEvent)
    {
    Q_UNUSED(mouseEvent);
    debug("Scene", "mouseDoubleClickEvent");
    }
    virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* mouseEvent)
    {
    Q_UNUSED(mouseEvent);
    debug("Scene", "mouseReleaseEvent");
    }
    };
    @

    Time: 35,827 -- Scene::mousePressEvent
    Time: 35,859 -- Scene::mouseReleaseEvent
    Time: 35,931 -- Scene::mouseDoubleClickEvent
    Time: 35,955 -- Scene::mouseReleaseEvent
    Time: 36,270 -- Scene::mousePressEvent
    Time: 36,510 -- Scene::mouseReleaseEvent
    Time: 36,123 -- Scene::mouseDoubleClickEvent
    Time: 36,163 -- Scene::mouseReleaseEvent
    Time: 36,219 -- Scene::mousePressEvent
    Time: 36,267 -- Scene::mouseReleaseEvent
    Time: 36,331 -- Scene::mouseDoubleClickEvent
    Time: 36,379 -- Scene::mouseReleaseEvent
    Time: 36,443 -- Scene::mousePressEvent
    Time: 36,483 -- Scene::mouseReleaseEvent
    Time: 36,547 -- Scene::mouseDoubleClickEvent
    Time: 36,595 -- Scene::mouseReleaseEvent
    Time: 36,643 -- Scene::mousePressEvent
    Time: 36,691 -- Scene::mouseReleaseEvent
    Time: 36,747 -- Scene::mouseDoubleClickEvent
    Time: 36,803 -- Scene::mouseReleaseEvent
    Time: 36,859 -- Scene::mousePressEvent
    Time: 36,899 -- Scene::mouseReleaseEvent
    Time: 36,955 -- Scene::mouseDoubleClickEvent
    Time: 37,270 -- Scene::mouseReleaseEvent


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.