Results 1 to 6 of 6

Thread: Drawing an object on picture

  1. #1
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Red face Drawing an object on picture

    Hi All
    I have a project now, I want to draw an object (Dial) on picture which is in a frame.I try to make a car indicator. I am using a picture as a background and i want to move a dial on it.
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drawing an object on picture

    And what is the problem?

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drawing an object on picture

    Quote Originally Posted by wysota View Post
    And what is the problem?
    He doesn't know how to draw the dial

    Better subclass the frame or a QWidget and draw the background image in the paint event.
    Next, draw a thin round rectangle from the paint event, from the indicator center, to whatever value you need.

    The mobile end of the dial should be controlled by some member in your class, such as the current speed, or angle. In the paint event you should paint the dial according to this value.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drawing an object on picture

    QPainter::rotate() might come in handy.

  5. #5
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Default Re: Drawing an object on picture

    today I achieved to do this, thank you for your interest.
    Qt Code:
    1. QPainter painter(this);
    2. int x1=0,y1=3,x2=0,y2=-3,x3=-90,y3=0;
    3. QPoint points[] = { QPoint(x1, y1), QPoint(x2, y2), QPoint(x3, y3) };
    4. painter.setRenderHint(QPainter::Antialiasing);
    5. QPixmap pixmap;
    6. pixmap.load("pencere.png");
    7. painter.drawPixmap(0,0,pixmap);
    8. painter.setPen(Qt::green);
    9. QLinearGradient coneGradient(40,100,300,350);
    10. coneGradient.setColorAt(0.5,Qt::white);
    11. coneGradient.setColorAt(0.1,Qt::green);
    12. coneGradient.setColorAt(1,Qt::black);
    13. QMatrix matrix;
    14. matrix.translate(0,20);
    15. matrix.rotate(a);
    16. painter.setMatrix(matrix);
    17. painter.setBrush(coneGradient);
    18. painter.setWindow(-107,-94,214,188);
    19. painter.drawPolygon(points,3);
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  6. #6
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Default Re: Drawing an object on picture

    Hi
    I have an other question, I will be appreciate if you answer it. I want to make an other two labels they will show battery level and A.D.C result.But they will have different backgorunds how may i do this . Do I have to make different classes for promoting and header files ? or may i use same class just make some changes in "paint event "which is i already used for above.

Similar Threads

  1. Replies: 3
    Last Post: 4th June 2007, 09:51

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
  •  
Qt is a trademark of The Qt Company.