Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Drag Button Screen Tear?

Drag Button Screen Tear?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 1.9k 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.
  • A Offline
    A Offline
    Andaharoo
    wrote on last edited by
    #1

    I implemented drag button by inheriting the QPushButton class and overriding mouseMoveEvent like so:

    void DragButton::mouseMoveEvent(QMouseEvent* e) 
    {
        if (e->buttons() == Qt::LeftButton)
        {
            QPoint extent = QPoint(width() * 0.5, height() * 0.5);
            move(mapToParent(e->pos() - extent));
            emit mouseMove(this);
        }
    }
    

    But whenever I drag it I get this, what looks like, screen tearing on the button? For the life of me I can't figure out why.
    alt text

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Are you also doing custom painting ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Andaharoo
        wrote on last edited by Andaharoo
        #3

        @SGaist I first had a button with a circular mask on it and it still did the tearing.

        But I've revisited the class recently and decided to look into this. The particular button in the image inherits DragButton and uses the paintEvent function to draw ellipses instead of applying a circular mask to the button. Lke this:

        void NodeButton::paintEvent(QPaintEvent* event)
        {
            QPainter p(this);
            p.setPen(Qt::NoPen);
            QBrush br = QBrush(Qt::gray, Qt::SolidPattern);
            p.setBrush(br);
            p.drawEllipse(0, 0, width(), height());
            br = QBrush(color, Qt::SolidPattern);
            p.setBrush(br);
            p.drawEllipse(2, 2, width() - 4, height() - 4);
        }
        

        I've read things are rendered with masks. So if I draw an item larger than the width and height of the button in the custom paint function it won't show. Could the masks position be lagging behind the position of the ellipse thus causing it to cut off the side of the ellipse?

        Maybe it's also worth noting that the button is in QMainWindow -> QDockWidget -> CustomWidget -> Inherited QPushButton

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Wouldn't it be more efficient to create a pixmap with that ellipse when resizing your widget and only draw that pixmap in the paint event ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          0
          • SGaistS SGaist

            Wouldn't it be more efficient to create a pixmap with that ellipse when resizing your widget and only draw that pixmap in the paint event ?

            A Offline
            A Offline
            Andaharoo
            wrote on last edited by Andaharoo
            #5

            @SGaist
            Doesn't solve the problem.

            I have numerous draggable buttons all of which could overlap and be different colors. I tried saving an ellipse to a 50, 50 pixmap and recoloring it but nothing I tried could recolor it.

            I don't know about the efficiency. Depends how qt implemented it. Pretty negligible. I did profile both of them in visual studios. They're really really close in performance. But I don't think efficiency is the problem.

            Perhaps there would be a large benefit using a pixmap instead if my buttons were larger in size.

            Edit: Initially did a 50, 50 pixmap test and the pixmap was slower. But it should have been 30, 30. I retested and the pixmap is like .2% faster.

            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