You didn't write what these pixels are representing, but if you want to display a spectrogram ( http://qwt.sourceforge.net/spectrogramscreenshots.html ) you can have a look at Qwt.i have an array of 360*250 which represent pixels.
Uwe
You didn't write what these pixels are representing, but if you want to display a spectrogram ( http://qwt.sourceforge.net/spectrogramscreenshots.html ) you can have a look at Qwt.i have an array of 360*250 which represent pixels.
Uwe
And if you want something really simple (plotting some pixels on a simple canvas) then subclass QWidget and reimplement paintEvent() and sizeHint().
In addition to the previous posters in this thread, you can also use QImage to manipulate pixels directly and then show it with a QPixmap.
All the above solutions are good, depending on your problem domain.
==========================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.
thanks to all for u r suggestions
i am trying all of the above methods one by one.
unfortunately i got stuck in the first try .
here is the code
Qt Code:
void bpg_graphicsview :: bpg_plot() { for (int i=0; i<LOOP; i++) for (int j=0; j<COL; j++) { x[0]= i * cos(j*DEGREE_TO_RADIAN); y[0]= i * sin(j*DEGREE_TO_RADIAN); x[1]= (i +1)* cos(j*DEGREE_TO_RADIAN); y[1]= (i +1)* sin(j*DEGREE_TO_RADIAN); x[2] =(i +1)* cos((j+1)*DEGREE_TO_RADIAN); y[2] =(i +1)* sin((j+1)*DEGREE_TO_RADIAN); x[3] = (i)* cos((j+1)*DEGREE_TO_RADIAN); y[3] = (i)* sin((j+1)*DEGREE_TO_RADIAN); qDebug()<<i<<" "<<j; this->update(); } qDebug()<<"end"; } { qDebug()<<"paint Event"; painter.setBrush(Qt::red); painter.drawPolygon(points, 4); }To copy to clipboard, switch view to plain text mode
this code works only when the contents of bpg_plot() are inside the paintEvent function
otherwise it never executes..
also,whenever update() is called the paintEvent does not work(qDebug()<<"paint Event"; does not print for every call).
please point where is the bug in the code .
If you want to use graphics view, you don't need to reimplement the paint event. Instead you have to add items to the scene. If you wish to use my approach, you can use the above code, just transform it so that it uses integer values.
yes wysota , i am following u r method ,i made the chage u said(changing to int values)
inspite ,of the change i am not getting any output .
my problem is simple , i change the points for the painter.drawPolygon(points, 4); function which is inside the paintEvent()function.
but the points are changed in the other function and whenever it is changed the update function is called to update() the diagram.
is there any way to draw a polygon without using paintEvent() on QWidget.
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
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.
Do you mean you have a matrix of 250 circles?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.)
By represent, do you mean draw?based on the value in the matrix i have to represent the circle(at every degree and radius) in different color.
and what do you mean with "at every degree and radius"?
A circle has a radius, and all the degrees in it....
here I lost you completely...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.
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.
NoDo you mean you have a matrix of 250 circles?
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.
do i definitely need to reimplement the paintEvent() function.
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.
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.
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:
#include <QWidget> #include <QPainter> #include <QPaintEvent> #include <QApplication> public: for(int i=0;i<360;i++){ data[i].r = (qrand()%(1000*200))/1000.0; } } protected: p.fillRect(rect(), Qt::white); for(int i=0;i<360;i++){ p.save(); p.translate(width()/2, height()/2); p.rotate(i); p.setPen(data[i].c); p.restore(); } } private: struct S { QColor c; float r; }; S data[360]; }; int main(int argc, char **argv){ Widget w; w.show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
babu198649 (11th December 2007)
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![]()
Bookmarks