Results 1 to 10 of 10

Thread: Graphics

  1. #1
    Join Date
    Mar 2010
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Graphics

    I'm trying to do some basic graphics. Basically, I have an array of non-negative values that represent distance from a point and the array index represents the angle. I want to draw an oval at the origin and a circle at each of these places. I also need this area where I'm drawing this stuff to reside inside a section on a form and the rest of the form will have other text data.

    Example:

    If the ary[90] contains the value 5000 (distance is in millimeters) then it would draw a small circle straight ahead of the oval at the origin.

    I have not done anything like this in Qt before so any resources, ideas, advice, etc is GREATLY appreciated.

    Thanks.

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

    Default Re: Graphics

    Take a look at QPainter or QGraphicsView as any of the two approaches can be used in your situation.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2010
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Graphics

    QPainter looks like what I need. I understand that it actually does the drawing, but what widgets can I use it on?

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

    Default Re: Graphics

    You can't use any widgets "on" it. It's a method of painting on widgets. You need to create a custom widget and draw it using QPainter in its paintEvent().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2010
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Graphics

    Gotcha. How does this look for a start.

    Qt Code:
    1. #ifndef MAPWIDGET_H
    2. #define MAPWIDGET_H
    3.  
    4. #include <QWidget>
    5. #include <QPainter>
    6.  
    7. class mapWidget : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. mapWidget(QWidget *parent = 0);
    13.  
    14. void setLMS(long data[]);
    15. void setCamera(long data[]);
    16. void draw(QPainter *painter);
    17.  
    18. private:
    19. long lmsData[1080];
    20. long cameraData[180];
    21.  
    22. protected:
    23. void paintEvent(QPaintEvent * event);
    24.  
    25. };
    26.  
    27. #endif // MAPWIDGET_H
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Graphics

    Looks fine, just make the constructor explicit, "just in case". I'd also suggest to replace those C array arguments with QVector or QList.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    TheDuncan (5th April 2010)

  8. #7
    Join Date
    Mar 2010
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Graphics

    I'll do that.

    How do you add a custom widget to a form?

  9. #8
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Graphics

    A custom widget is still a widget, you can directly show it using QWidget::show, or you can add it to any other widget in that widgets layout.
    Give some time exploring the examples and documentation.

  10. The following user says thank you to aamer4yu for this useful post:

    TheDuncan (5th April 2010)

  11. #9
    Join Date
    Mar 2010
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Graphics

    Ok, but where do I use those commands? In main? Do How do I limit the space or assign where on the form the widget appears?

  12. #10
    Join Date
    Mar 2010
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Graphics

    Thanks for all the help. Works like a champ

Similar Threads

  1. Qt-Graphics
    By grsandeep85 in forum Qt Programming
    Replies: 3
    Last Post: 30th October 2009, 09:33
  2. Qt Graphics
    By soumya in forum Qt Programming
    Replies: 1
    Last Post: 27th October 2009, 09:41
  3. Qt Graphics
    By soumya in forum Qt Programming
    Replies: 8
    Last Post: 19th August 2009, 12:12
  4. 3D graphics
    By impeteperry in forum Qt Programming
    Replies: 3
    Last Post: 19th July 2009, 08:00
  5. Qt graphics
    By ShaChris23 in forum Newbie
    Replies: 1
    Last Post: 22nd May 2007, 06: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.