How to set logarithmic scale on a QGraphicsView ?



  • I'm using the QGraphicsView framework to plot a bezier curve and I need to plot it using a logarithmic scale. But I've been unable to find anything that would set a logarithmic scale in the view.

    Is there anything available by default (maybe QGraphicsView::transform() ?) to ease my work ?
    If not, then any suggestions on how to achieve this are greatly appreciated.



  • There's no built-in way I know of. But you might wish to take a look at "QWT":http://qwt.sourceforge.net/



  • I have searched more about plotting Log scales and it seems there's nothing easier than extending the linear range to that of a logarithmic range, and then draw with logarithmic coordinates.
    Assuming the linear axis sizes are X=[0:width] and Y=[0:height] and a point has linear coordinates P=[x, y], then you have to translate those into log coordinates:
    xAxis = [log10(0) : log10(width)]
    yAxis = [log10(0) : log10(height)]
    P = [log10(x), log10(y)]

    I'm not sure if I have correctly understood this so if anyone can point out why my reasoning is wrong please tell me. Personally I think I'm mistakenly assuming that a point P shall be drawn at the log coordinates since this will be like having a linear axis with linear coordinates... I still have to try this.



  • By "no built-in way" I meant there's no ready-to-use logarithmic transformation class, or such.
    There's nothing wrong with doing the required calculations yourself. All you need to do is mapping a logarithmic coordinate space to a linear coordinate space - basically what you do with 'P' above.



  • Thank you for help Asperamanca. yes, I understood what you meant by "no built-in way" above and it's not a problem for me to implement the necessary calculations. The real issue was to find out how to make it happen since I wasn't sure of which conversions Lin->Log I should apply (either point coordinate conversion or space size extension, or both). I'm now going to try a few combinations and check which one is right :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.