Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML 2 performance is worse than QML 1?
Forum Updated to NodeBB v4.3 + New Features

QML 2 performance is worse than QML 1?

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 959 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zvava
    wrote on last edited by
    #1

    I have an application on Qt4 with ma own class derived from QDeclarativeItem.
    Here it is:
    PaintArea.h Qt4
    @class PaintArea : public QDeclarativeItem
    {
    Q_OBJECT
    public:
    explicit PaintArea(QDeclarativeItem *parent = 0);
    ~PaintArea();

    protected:
    void mousePress(QGraphicsSceneMouseEvent *event);
    void mouseMove(QGraphicsSceneMouseEvent *event);
    void paint(QPainter *p, const QStyleOptionGraphicsItem *s, QWidget *w);
    void updateBufferRect(const QLine &line);
    void modifyUpdateRect(const QPoint& left, const QPoint& right);
    bool sceneEvent(QEvent *event);

    private:
    QPoint m_firstPoint;
    QPoint m_lastPoint;
    QPixmap *m_pix;
    QRect m_updateRect;
    bool m_isPainted;
    };@

    PaintArea.cpp Qt4
    @PaintArea::PaintArea(QDeclarativeItem *parent) :
    QDeclarativeItem(parent)
    {
    setFlag(QGraphicsItem::ItemHasNoContents, false);
    setAcceptedMouseButtons(Qt::LeftButton);

    m_pix = new QPixmap(1920, 1080);
    m_pix->fill(Qt::transparent);
    

    }

    PaintArea::~PaintArea()
    {
    delete m_pix;
    }

    void PaintArea::paint(QPainter *p, const QStyleOptionGraphicsItem *s, QWidget *w)
    {
    p->drawPixmap(m_updateRect, *m_pix, m_updateRect);
    m_isPainted = true;
    }

    void PaintArea::mousePress(QGraphicsSceneMouseEvent *mev)
    {
    m_isPainted = false;
    m_firstPoint = m_lastPoint = mev->pos().toPoint();
    }

    void PaintArea::mouseMove(QGraphicsSceneMouseEvent *mev)
    {
    m_firstPoint = m_lastPoint;
    m_lastPoint = mev->pos().toPoint();

    QPoint topLeft = m_firstPoint;
    QPoint bottomRight = m_lastPoint;
    
    if (topLeft.x() > bottomRight.x()){
        int temp = topLeft.x();
        topLeft.setX(bottomRight.x());
        bottomRight.setX(temp);
    }
    if (topLeft.y() > bottomRight.y()){
        int temp = topLeft.y();
        topLeft.setY(bottomRight.y());
        bottomRight.setY(temp);
    }
    
    QPainter p(m_pix);
    p.setPen(QPen(QBrush(Qt::red), 3));
    p.setRenderHint(QPainter::Antialiasing);
    p.drawLine(m_firstPoint, m_lastPoint);
    
    if (m_isPainted)
        m_updateRect = QRect(topLeft, bottomRight);
    else
        m_updateRect |= QRect(topLeft, bottomRight);
    
    m_isPainted = false;
    
    update(m_updateRect.adjusted(2, 2, -2, -2));
    

    }

    bool PaintArea::sceneEvent(QEvent *event)
    {
    switch(event->type())
    {
    case QEvent::GraphicsSceneMouseDoubleClick:
    break;
    case QEvent::GraphicsSceneMousePress:
    mousePress(dynamic_cast<QGraphicsSceneMouseEvent *>(event));
    event->accept();
    return true;
    break;
    case QEvent::GraphicsSceneMouseMove:
    mouseMove(dynamic_cast<QGraphicsSceneMouseEvent *>(event));
    break;
    default:
    return QDeclarativeItem::event(event);
    }
    return false;
    }@

    I use it in QML. And performance in QML 1 is great.
    But when I've migrated to Qt5 performance decreased significantly (a lot of angles in my line)

    PaintArea.h Qt5
    @class PaintArea : public QQuickPaintedItem
    {
    Q_OBJECT
    public:
    explicit PaintArea(QQuickItem *parent = 0);

    void paint(QPainter *p);
    
    void mousePressEvent(QMouseEvent *mev);
    void mouseMoveEvent(QMouseEvent *mev);
    

    private:
    QPoint m_firstPoint;
    QPoint m_lastPoint;
    QPixmap *m_pix;
    QRect m_updateRect;
    bool m_isPainted;
    };@

    PaintArea.cpp Qt5
    @PaintArea::PaintArea(QQuickItem *parent) :
    QQuickPaintedItem(parent)
    {
    setAcceptedMouseButtons(Qt::LeftButton);

    setRenderTarget(FramebufferObject);
    m_pix = new QPixmap(1920, 1080);
    m_pix->fill(Qt::transparent);
    

    }

    void PaintArea::paint(QPainter *p)
    {
    p->drawPixmap(m_updateRect, *m_pix, m_updateRect);
    m_isPainted = true;
    }

    void PaintArea::mousePressEvent(QMouseEvent *mev)
    {
    m_isPainted = false;
    m_firstPoint = m_lastPoint = mev->pos();
    }

    void PaintArea::mouseMoveEvent(QMouseEvent *mev)
    {

    m_firstPoint = m_lastPoint;
    m_lastPoint = mev->pos();
    
    QPoint topLeft = m_firstPoint;
    QPoint bottomRight = m_lastPoint;
    
    if (topLeft.x() > bottomRight.x()){
        int temp = topLeft.x();
        topLeft.setX(bottomRight.x());
        bottomRight.setX(temp);
    }
    if (topLeft.y() > bottomRight.y()){
        int temp = topLeft.y();
        topLeft.setY(bottomRight.y());
        bottomRight.setY(temp);
    }
    
    QPainter p(m_pix);
    p.setPen(QPen(QBrush(Qt::red), 3));
    p.setRenderHint(QPainter::Antialiasing);
    p.drawLine(m_firstPoint, m_lastPoint);
    
    topLeft -= QPoint(4, 4);
    bottomRight += QPoint(4, 4);
    
    if (m_isPainted)
        m_updateRect = QRect(topLeft, bottomRight);
    else
        m_updateRect |= QRect(topLeft, bottomRight);
    
    m_isPainted = false;
    
    update(m_updateRect);
    

    }@

    Someone said me that QML 2 repaint ALL QQuickView area and when it paints the main thread is frozen and miss MouseEvents... Is it true? How to avoid this?
    How to increase performance on Qt5?

    PS. I've tried to use acceleration:
    @qputenv("QML_FORCE_THREADED_RENDERER", "1");
    qputenv("QT_QPA_EGLFS_FORCEVSYNC", "1");@

    but it lags too (

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved