Results 1 to 4 of 4

Thread: QPainter-design issues.

  1. #1

    Question QPainter-design issues.

    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 -_-!

  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: QPainter-design issues.

    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.

  3. #3

    Exclamation Re: QPainter-design issues.

    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?

  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: QPainter-design issues.

    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?

Similar Threads

  1. Replies: 7
    Last Post: 20th March 2006, 20:03

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.