Results 1 to 3 of 3

Thread: Widget dragging, widget doesn't fully draw

  1. #1
    Join Date
    Jul 2012
    Posts
    2

    Default Widget dragging, widget doesn't fully draw

    I created a widget that I can drag around the window. As the widget is being dragged, part of it doesn't draw fully, especially when dragging at faster speeds.

    For example, while dragging the widget to the left, the left few pixels of the widget don't get drawn.

    It's acting as if the widget is getting moved, but is clipped on the edge in the direction of the movement. This is a very simple widget and so moving/drawing it should be pretty quick (it's just a colored rectangle).

    Basically, I'm just capturing a mousePressEvent, and then dragging the widget using move() based on the new mouse position in the mouseMoveEvent. I've tried various combinations of repaints and updates, but they don't seem to make any difference.

    Any suggestions on how to make this more 'snappy'?

    Qt Code:
    1. void PaletteControl::mousePressEvent(QMouseEvent* evt)
    2. {
    3. mouseDown = true;
    4. mouseStartPoint = evt->pos();
    5. }
    6.  
    7. void PaletteControl::mouseMoveEvent(QMouseEvent* evt)
    8. {
    9. if (mouseDown) {
    10. mouseDragging = true;
    11. }
    12.  
    13. if (mouseDragging) {
    14. QPoint newPoint = evt->pos();
    15. int deltaX = newPoint.x() - mouseStartPoint.x();
    16. int deltaY = newPoint.y() - mouseStartPoint.y();
    17.  
    18. QPoint pos = this->pos();
    19. move(pos.x() + deltaX, pos.y() + deltaY);
    20. update();
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Widget dragging, widget doesn't fully draw

    use graphics view which will do this for you.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Jul 2012
    Posts
    2

    Default Re: Widget dragging, widget doesn't fully draw

    amleto, thank you for the suggestion. In fact, my widget eventually will contain controls and will be dragged around the QMainWindow, and so using the graphics view doesn't work for my purposes. I tried using a QDockWidget, but it has some undesired behaviors.


    Added after 1 55 minutes:


    I think I figured it out. It seems the parent widget needs to be told to update itself when one of its children is moved (outside of a layout). Calling parentWidget()->update() after the move() fixes the drawing issue.
    Last edited by Meate; 31st July 2012 at 22:21.

Similar Threads

  1. how to draw a widget on another widget?
    By hashb in forum Qt Programming
    Replies: 5
    Last Post: 28th May 2012, 11:25
  2. Replies: 0
    Last Post: 23rd May 2010, 15:10
  3. Is there a widget fully support html in QT4?
    By hashb in forum Qt Programming
    Replies: 2
    Last Post: 15th October 2009, 02:05
  4. Draw contents of widget in another widget
    By gustavosbarreto in forum Qt Programming
    Replies: 1
    Last Post: 6th August 2007, 14:43
  5. Widget dragging in MDI app
    By zeeeend in forum Qt Programming
    Replies: 3
    Last Post: 17th January 2007, 21:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.