[solved]Strange behavior of QML Elements written in Qt
Hello guys,
I’ve written my own component in Qt and exposed it to QML to use it in another component.
So long everything works fine.
But when I add my new Component twice on my window, the first one gets rendered as expected, but the second one has the font of the title.
To make my Problem a little bit more clear I try to give an example:
- Item {
- Text { // a caption
- font.bold: true
- ...
- }
- MyComponent { // written in Qt, paints a timeline with text underneath
- ...
- }
- }
My component looks something like this. I have a Text item as caption, and a small timeline where everything is painted in Qt (the line + text)
5 replies
- Rectangle {
- id: rect1
- Text {
- id: text1
- font.bold: true
- font.pointSize: 20
- }
- MyQtComponent{
- id: other1
- ... //(mostly anchors)
- }
- }
- Rectangle {
- id: rect2
- Text {
- id: text2
- font.bold: true
- font.pointSize: 20
- }
- MyQtComponent {
- id: other2 // draws some text with QPainter inside qt, not qml, this one gets the font settings of text1
- ...
- }
- }
In MyQtComponent I use QPainter to draw some text without setting a font explicit.
The problem I have is, that as long as the font settings of text1 is set to 20 and bold, the font of other2 is also in this font setting. The font of other1 is normal. Both components are on the same window.
Hi,
QDeclarativeView sets the QGraphicsView::DontSavePainterState optimization flag by default, which means any changes you make to the painter (such as painter->setFont()) in your paint() function need to be undone at the end of the paint() function, or they may “leak” to other items.
Regards,
Michael
You must log in to post a reply. Not a member yet? Register here!


