PDA

View Full Version : QPainter-design issues.



regrant
29th May 2008, 21:38
Hi all

I am developing a little project that uses algorithms to solve point-based problems. I've designed a class diagram in which everything is slightly related. In order to improve the results, I think it's necesary to visualize the solutions while the algorighm finds them. The algorithms are supposed to start with one solution and then, it changes this solution (for example, by applying a shuffle) in order to get a better solution.

There is a solution class that stores and handles the solutions. I would like this class to have a paint() method to paint the current solution in a pop-up window. So, when the algorithm finds a new solution, paint() method would be called and when you close the window, the algorithm would keep on finding new solutions. Is there any way to do this with QPainter? I thought it might be possible to create a virtual class paintSolution with a virtual method "paint()". So the 'solution class' would inherit from this class implementing paint() method to draw its parameters. I do want to separate QT window-ish and paint-ish stuff from the main program. Could you throw me ideas on how to do that?

Thanks in advance :)

P.S: I am sorry about my english, if you don't understand something please let me know -_-!

wysota
29th May 2008, 22:29
Simply reimplement the paintEvent for the window you want to draw in and call your class paint() implementation there. And call update() on the widget when you want it redrawn. Alternatively you can use event filters to avoid reimplementing the paint event.

regrant
29th May 2008, 22:36
Thanks a lot for your answer ^^

But in order to display a Windows with the solution painted, isn't necesary to create a QApplication object in the main function? is there a way to avoid this?

wysota
29th May 2008, 23:24
No, there is no way to avoid it (unless you are asking about the place to create the object). You need an event loop running for the windows to be reactive (visible included). What's wrong with creating the application object?