[Note: I prefer PyQt, but an answer for Qt is the same as far as I am concerned. I understand both languages.]
Question:
I would like to render a string, for example: ‘Hello world!’ (nothing fancy). I DO NOT want to do this through a proxy, such as QTextEdit or QWebKit. Rather, I want full control of the rendering on a low level – each character. The issues/questions are:
-
Which widget should I use (for quickest rendereing) QGraphicsWidget?
-
Given a position (x,y), how do I then render an image of the character on the screen?
-
The text may span multiple lines. Should I render an image of each character to the screen one by one, or should I first create an ‘image’ of the line, and then render each line (I assume this would aid in the speed of scrolling, as wouldn’t have to recalculate every character, only move the line up or down)? If the latter, how do I create that image?
-
How would I go about highlighting a selection as the user drags his mouse over it – would I have to rerender the character, or just do some ‘background color’ operation on that position of the screen?
Please, I would appreciate if you could answer in a practical manner – i.e. specific methods/classes/etc. (not just a vague idea like ‘display it’ – but how?).
Thanks!
Implementing a custom
QWidgetby overloading theQWidget::paintEventand using a painter is about the lowest level in Qt using the widget system.Here is a full working example using C++ I’ve put together for you, I don’t know PyQt but hopefully you can port this!
widget.h
widget.cpp
test.cpp
test.pro