PDA

View Full Version : Problems with QGraphicsItems



JonathanForQT4
24th April 2007, 11:00
Hello all,

So I'm now having some troubles with QGraphicsItems....specifically when I want to print QGraphicsTextItem. When I print the text to my scene, I can't see it because the scale of the scene shrinks the text too much. So when use scale to enlarge the scene, the text becomes larger...but then too large....
Any ideas how to make this text a static size, just like my QGraphicsLineItem, which always stays of pixel width one regards of the scale from the scene?

Second problem is when I draw a QGraphicsLineItem between two points and it is either _perfectly_ horizontal or vertical, then it will not disappear unless I minimize the window.... this is my code...



if(showMeasureLine){
m_MeasureLine->show();
m_MeasureLine->setLine(QLineF(m_measureDistStartPoint,m_currentMo usePos));
}
else{
MeasureLine->hide();
MeasureLine->update();
}

this code is within mouseMoveEvent(QMouseEvent *event)....
it works for when the line is diagonal etc. but not when 90, 180, 270 or 360 degrees

Bitto
24th April 2007, 17:42
You're probably looking for ItemIgnoresTransformations (http://doc.trolltech.com/4.3-snapshot/qgraphicsitem.html#GraphicsItemFlag-enum), a new flag appearing in the upcoming Qt 4.3. It ensures that the item stays the same size also when you zoom in or out.

aamer4yu
25th April 2007, 06:00
if(showMeasureLine)
{ m_MeasureLine->show();
m_MeasureLine->setLine(QLineF(m_measureDistStartPoint,m_currentMo usePos));
}
did u try caling update after setting the line ??

JonathanForQT4
25th April 2007, 08:34
hey, thanks for your post Andreas!! I'm looking forward to when 4.3 is released, unfortunately I can't use 4.3, do you have any suggestions about how I could do this until 4.3 comes out? maybe putting a widget over the viewport or something and print on the widget?
I've tried this, but had troubles centering the widget/keeping it the same size as the viewport from the QGraphicsView and being able to click on the overlaying widget and having the viewport pick it up.
Any clues as to when 4.3 will be released?
in any case, thanks again :)

aamer4yu, tried calling update after this line, but that doesn't work. I am surprised because it should be the following that should cause it to disappear.
m_MeasureLine->hide();
m_MeasureLine->update();

Any other ideas?

another eidt://I have just tried adding the item each time to the scene and removing it from the scene each time....still doesn't work...:(

aamer4yu
25th April 2007, 11:49
can we see the minimal code that causes the problem ??

JonathanForQT4
26th April 2007, 08:25
um, the code I have posted is the only time I do anything with m_Measureline, so this must be the code the causes the problem.... the only other place I mention anything is in the constructor: m_MeasureLine = new QGraphicsLineItem(0, m_mainScene);

I'm starting to guess that when the line is vertical or horizontal the Qt background code stores it on the scene in a different way and that's why it stays there even when I do a refresh....so...dare I say a bug with Qt!!