Results 1 to 20 of 20

Thread: suitable class for plotting pixels

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: suitable class for plotting pixels

    Quote Originally Posted by babu198649 View Post
    unfortunately i got stuck in the first try .
    Your code tries to paint a polygon, what is something very different than plotting pixels ( for what you got answers ).
    Maybe it's better to go one step back and explain more detailed, what your "pixels" are and how do you want to display them.

    Do you want to display something like curves in a diagram ?

    Uwe

  2. #2
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: suitable class for plotting pixels

    ok ume i explain in detail
    i have an array of size[360*250] .it represents the degrees of a circle and radius.(for each corresponding degree and radius i have a value in the matrix.)

    based on the value in the matrix i have to represent the circle(at every degree and radius) in different color.

    so i made a polygon (the area between the angles and a unit radius) and colouring the circle based on the value in the matrix.

    thus i need to fill the polygon with different color after computing the polygon coordinates.

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: suitable class for plotting pixels

    have an array of size[360*250] .it represents the degrees of a circle and radius.(for each corresponding degree and radius i have a value in the matrix.)
    Do you mean you have a matrix of 250 circles?
    based on the value in the matrix i have to represent the circle(at every degree and radius) in different color.
    By represent, do you mean draw?
    and what do you mean with "at every degree and radius"?
    A circle has a radius, and all the degrees in it....

    so i made a polygon (the area between the angles and a unit radius) and colouring the circle based on the value in the matrix.
    here I lost you completely...
    Why don't you use QPainter::drawEllipse()?
    And set the brush with the color you want?

    You might want to have a look at QPainter::drawChord() and QPainter::drawPie() too
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. #4
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: suitable class for plotting pixels

    Do you mean you have a matrix of 250 circles?
    No

    i have only one circle , the circle is divided in to [360]*[250] parts which i called it as matrix.

    for every value in matrix representing the circle in different color .

    so dividing the circle in to polygons(360*250 polygons) and filling the polygons with different colors.

    after finding the points of every polygon i fill the polygon(this is where i got struck) ,before finding the points for the next.

    finding the polygon values occur in the loops.

  5. #5
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: suitable class for plotting pixels

    do i definitely need to reimplement the paintEvent() function.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: suitable class for plotting pixels

    Oh ok I see. (sorry for being the slow one)
    Then I join wysota and Uwe - QPainter::drawPie().
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: suitable class for plotting pixels

    thanks for all of u r cooperation .

    even though i am drawing a circle i have an algorithm that has four points and i should definitely need the polygon function.

    but is there any way to draw polygon on QWidget without using paintEvent function.
    Last edited by babu198649; 10th December 2007 at 12:39.

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

    Default Re: suitable class for plotting pixels

    No, there is none.

    You want to obtain something like in the attachment (it draws lines instead of polygons, but the idea is similar)?

    Qt Code:
    1. #include <QWidget>
    2. #include <QPainter>
    3. #include <QPaintEvent>
    4. #include <QApplication>
    5.  
    6. class Widget : public QWidget {
    7. public:
    8. Widget() : QWidget(){
    9. for(int i=0;i<360;i++){
    10. data[i].c = QColor(qrand()%256, qrand()%256, qrand()%256);
    11. data[i].r = (qrand()%(1000*200))/1000.0;
    12. }
    13. }
    14. QSize sizeHint() const { return QSize(200,200); }
    15.  
    16. protected:
    17. void paintEvent(QPaintEvent *){
    18. QPainter p(this);
    19. p.fillRect(rect(), Qt::white);
    20. for(int i=0;i<360;i++){
    21. p.save();
    22. p.translate(width()/2, height()/2);
    23. p.rotate(i);
    24. p.setPen(data[i].c);
    25. p.drawLine(QPointF(0,0), QPointF(data[i].r, 0));
    26. p.restore();
    27. }
    28. }
    29. private:
    30. struct S {
    31. QColor c;
    32. float r;
    33. };
    34. S data[360];
    35.  
    36. };
    37.  
    38. int main(int argc, char **argv){
    39. QApplication app(argc, argv);
    40. Widget w;
    41. w.show();
    42. return app.exec();
    43. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

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

    babu198649 (11th December 2007)

  10. #9
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Smile Re: suitable class for plotting pixels

    thank u wysota
    i realize the pain u have taken to code the above program( this is the second time u r taking pain for me).
    the problem was with save() and restore(). initiallly i have not used these functions.

    at first i followed the Basic Drawing Example and i have not noticed the save() and restore() function.
    i should have been careful while reading docs to save u the pain

    thanks again

  11. #10
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: suitable class for plotting pixels

    Quote Originally Posted by babu198649 View Post
    based on the value in the matrix i have to represent the circle(at every degree and radius) in different color.
    Ok, then forgot all you read about QImage and QPixmap.

    I recommend to follow Witolds suggestion and use a simple QWidget ( QGraphicsView is pointless overhead here, that gives you more trouble than solution ). Then use QPainter::drawArc ( or drawPie ? )

    HTH,
    Uwe

Similar Threads

  1. Connecting to a base class signal?
    By AaronMK in forum Qt Programming
    Replies: 4
    Last Post: 26th October 2007, 22:37
  2. Creating object of other class in Run() method
    By santosh.kumar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2007, 15:05
  3. Replies: 2
    Last Post: 16th March 2007, 09:04
  4. Replies: 2
    Last Post: 4th May 2006, 19:17
  5. How to propagate from one class to another
    By mahe2310 in forum Qt Programming
    Replies: 15
    Last Post: 20th March 2006, 01:27

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.