开发者

Need a little help with the Qt painting classes

I'm trying to write a paint program (paint where ever a mouse press/hold is detected), but I'm having trouble using the Qt QPainter. I have read the documentation on their web site and I'm still kind of lost. A link to a tutorial that isn't on their web site would be nice or maybe explain to me how I can accomplish this in Qt. The onl开发者_如何学JAVAy thing I have managed to do is paint dots on a widget.


Check the Scribble example that comes with Qt, it does exactly what you want.

We reimplement the mouse event handlers to implement drawing, the paint event handler to update the application and the resize event handler to optimize the application's appearance. In addition we reimplement the close event handler to intercept the close events before terminating the application.

The example also demonstrates how to use QPainter to draw an image in real time, as well as to repaint widgets.


Use the QtAssistant and browse to the entry on QPainter. From there you will see links to example programs using various functions of QPainter, such as this one: http://doc.trolltech.com/4.5/painting-basicdrawing.html

QtAssistant should be your number one resource. It's quite thorough. Then if that doesn't help I recommend the forums at QtCentre. Those are some knowledgeable guys.


I can only guess what your problem is, but my guess is that you're running into the age old issue of the fact that the paintEvent is used to update the page. The way to implement a paint program would be to first create a QPixmap or QImage as your drawing buffer. Then paint on it in your mouse press/move/release methods. When you have updated the drawing buffer, all updated (and be a good boy and indicate the area in need of updating). This will trigger a call to your paintEvent method, where you simply blit the requested rectangle (QPaintEvent::rect()) to the screen.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜