Results 1 to 3 of 3

Thread: Rotation problem trying to draw a compass widget

  1. #1
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Rotation problem trying to draw a compass widget

    Hi everybody,

    I am developping a custom widget, a compass, composed of a background pixmap and a foreground pixmap (the cursor).

    My paintEvent code is a s follow :
    Qt Code:
    1. QPainter painter(this);
    2.  
    3. painter.drawPixmap(0, 0, *m_pBackground);
    4. painter.rotate(m_dAngle);
    5. painter.drawPixmap(0, 0, *m_pForeground);
    To copy to clipboard, switch view to plain text mode 

    The problem here is that after being rotated, the foreground pixmap is not centered over the background pixmap center.

    I think I must code something like this :
    Qt Code:
    1. QPainter painter(this);
    2.  
    3. painter.drawPixmap(0, 0, *m_pBackground);
    4. painter.rotate(m_dAngle);
    5. painter.translate(x, y);
    6. painter.drawPixmap(0, 0, *m_pForeground);
    To copy to clipboard, switch view to plain text mode 
    but how to determine x and y ?

    It would be great if anybody could give me a clue.

    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rotation problem trying to draw a compass widget

    Quote Originally Posted by yellowmat View Post
    I think I must code something like this :
    ...
    but how to determine x and y ?
    Try:
    Qt Code:
    1. int x = m_pBackground->width() / 2; // or width() if it's the same
    2. int y = m_pBackground->height() / 2;
    3.  
    4. painter.drawPixmap(0, 0, *m_pBackground);
    5.  
    6. painter.translate(-x, -y);
    7. painter.rotate(m_dAngle);
    8. painter.translate(x, y);
    9.  
    10. painter.drawPixmap(0, 0, *m_pForeground);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Rotation problem trying to draw a compass widget

    It works fine.

    Thanks

Similar Threads

  1. QDockWidget/Central Widget Problem
    By Lemming in forum Qt Programming
    Replies: 7
    Last Post: 3rd April 2016, 09:52
  2. Problem applying setWindowOpacity to a custom Widget
    By yellowmat in forum Qt Programming
    Replies: 8
    Last Post: 1st November 2006, 10:05
  3. Replies: 3
    Last Post: 12th April 2006, 08:20
  4. Widget resizing problem
    By fwohlfert in forum Qt Programming
    Replies: 3
    Last Post: 23rd February 2006, 08:16
  5. Replies: 7
    Last Post: 3rd February 2006, 10:20

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.