Unsolved setSceneRect() behaves differently?
-
@Pl45m4 ok, this is great as I like my coordinate system to be (0,0) in the top left corner like in
QWidget
-
@JonB Yes, scaling will work for some items but for others not so much. For example, I have texts in my scene and I have a few rectangles that depend on the size of the texts. As far as I know (I haven't tested it yet) that the texts will not scale while rectangles will, this would make the rectangles that depend on texts to be out of sync. I am going to test this feature now to see exactly how it works. So, my current plan is to have graphics items as member variables and then recalculate their positions on each resize and then reposition them accordingly (that is how I was doing it in
QWidget
, except inQWidget
I had to repaint the entire thing on each resize). Would you suggest differently? -
@CJha
I really don't know what you're trying to achieve. I don't know why you are changing the scene dimensions to fit the view, I don't know why you are proposing to recalculate/resize/move a whole bunch if scene items in any circumstances. Though I will say I have not put texts on gfx scenes, if that makes a difference. -
@CJha said in setSceneRect() behaves differently?:
So, my current plan is to have graphics items as member variables and then recalculate their positions on each resize and then reposition them
You dont need to store them, your scene knows ;)
You just have to filter them, if needed
https://doc.qt.io/qt-5/qgraphicsscene.html#items@JonB said in setSceneRect() behaves differently?:
texts on gfx scenes
I hope @CJha is talking about
QGraphicsTextItem
and not labels or other text :) -
@Pl45m4
Does aQGraphicsTextItem
scale for you (if you do scaling) like any other gfx item, without you being responsible to go in pick font sizes to fit, like you would have to do in a widget? -
@JonB I am making a line-plot. I have text for axis and tick labels in there. What I want is easy interaction with texts and other parts so that I can give the user the ability to easily change stuff (e.g. double click on axis label to get to it's settings, double click on plot lines to select it, etc.). Since, the entire plot should be visible at all times in the view, so if the view is resized I will have to recalculate/resize/move all stuff. I don't see a way around it.
-
@Pl45m4 Ah, ok. If my scene knows then that's even better. Yes, I am talking about
QGraphicsTextItem
and not labels, etc. -
@JonB said in setSceneRect() behaves differently?:
Does a QGraphicsTextItem scale for you (if you do scaling) like any other gfx item, without you being responsible to go in pick font sizes to fit, like you would have to do in a widget?
No, of course not. It scales but it doesn't ensure that it looks good afterwards.
Interesting example
https://stackoverflow.com/a/32188957@CJha said in setSceneRect() behaves differently?:
I am making a line-plot.
Why are you using
QGraphicsView
and not aQChart
or something similar? -
@Pl45m4 I tried
QChart
,QCustomPlot
and a few others. All of these are very slow when it comes to plotting a vector of hundreds of thousands of doubles. I made my own algorithm which runs in a different thread to do the calculations, this way I get around 10 times faster response as compared toQChart
. -
@CJha said in setSceneRect() behaves differently?:
hundreds of thousands of doubles
Which human can read hundreds of thousands data points in one plot?
Use downsampling to reduce the number of data points shown at a time and show the real data (range between given values), when zoomed in. -
@Pl45m4 I tried downsampling. It is not useful as I have to be accurate in showing the results since the plot is going to be used in scientific applications in labs. Downsampling is not useful because let's say I have one data point out of hundreds of thousands which is significantly different compared to others (usual case in real recorded data) then this might be lost in downsampling or it's magnitude might get changed (depending on the downsampling algorithm). This behaviour will not be acceptable in the labs that I am making the plot for.
I have already developed the algorithm to correctly show all the data points, it will show even a single data point out of hundreds of thousands which is significantly different from others without sacrificing its magnitude. This means even if the entire data of hundreds of thousands is visible at the same time, any inconsistencies, no matter how few data points it consists of, will always be visible to the scientist working with my plot.
Plotting is no longer an issue for me as I have separate threads which calculates the plot lines (one thread per plotline). The user interaction is an issue since the plot is going to be used in multiple circumstances e.g. to view already recorded data, to view real-time data from hardware measuring equipment, and to view user-constructed data.