'QGraphicsItem text strecthed on rescale
I am currently working on a project which consists to create a video editing timeline in Qt.
The project contains 2 key elements : the Timeline View ( QGraphicsView ) where we can add/delete video fragments ( QGraphicsItem ) and the Timeline Scheduler placed above indicating current scene's duration in seconds.
The fragments' dimensions are expressed in seconds directly in the item coordinate system. Therefore, the View's transformation matrix QGraphicsView.setTransform( viewWidth / sceneDuration, 1.0 ) is used to rescale the items' size in seconds to their corresponding size in pixels (see image2).
The items added to the view should have a name, which is represented by a simple text field painted via the following scheme : painter->drawText( QPoint ( 0, itemHeight / 2 ), itemName ). This is done directly in paint() method of the video fragments.
The problem is : as far as the video fragments are rescaled from the items' local coordinates in order to fit the view dimensions (pixel to seconds ratio), the items' text field is also stretched giving a rather weird result (see image1/fig.1 below). I tried calling font.setStretch(stretch) method in order to shrink the output yet it seems like any stretch value below 20 won't work (image1/fig.1 -- stretch factor in range a of 1 to 19), and the little values that match give a strange result as well with unequally spaced letters (image1/fig.2).
Anyway, I would like to set a stretch value that could correspond to (view width in pixels/total scene duration in seconds) ,790px / 100s in the example below, which would not necessarily fit to the stretch's value lower limit. Plus, redefining QGraphicsItem paint() method in items' coordinates (in seconds) implies applying the scaling twice, which may be problematic for the text stretch value and also for images, whose dimensions can become null.
Any solutions?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
