Results 1 to 17 of 17

Thread: Scaling

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Location
    Saint-Petersburg
    Posts
    50
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Scaling

    Hi!
    How to do scaling of my graphics by Qt means?

    Thanks for helps!

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    6
    Thanked 163 Times in 151 Posts

    Default Re: Scaling

    What graphics? Be more specific, please!

  3. #3
    Join Date
    Jun 2008
    Location
    Saint-Petersburg
    Posts
    50
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Re: Scaling

    Quote Originally Posted by caduel View Post
    What graphics? Be more specific, please!
    Graphics of dependence one parameter in other parameter! It is not important!
    The dialog that is shown this graphic with grid! What do you know some more?

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    6
    Thanked 163 Times in 151 Posts

    Default Re: Scaling

    Assuming that you are showing an image, use QImage::scaled, if your graphics are in the form of a QPixmap, use QPixmap::scaled...

    If that is not what you would like to know:
    give us more information! Your question is not really precise and I am wondering what you are trying to do. Hard to give advice that way.

    If you would give us a few lines of your code and say what is not working the way you want it to, you would save us time and get more helpful answers.

    HTH

  5. #5
    Join Date
    Jun 2008
    Location
    Saint-Petersburg
    Posts
    50
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Re: Scaling

    Quote Originally Posted by caduel View Post
    Assuming that you are showing an image, use QImage::scaled, if your graphics are in the form of a QPixmap, use QPixmap::scaled...

    If that is not what you would like to know:
    give us more information! Your question is not really precise and I am wondering what you are trying to do. Hard to give advice that way.

    If you would give us a few lines of your code and say what is not working the way you want it to, you would save us time and get more helpful answers.

    HTH
    I understand you My code that became out of date (Manual scaling, not Qt)! Tommorow I'll can give my new code! Concrete questions will appear tommorow! Thanks.

  6. #6
    Join Date
    Jun 2008
    Location
    Saint-Petersburg
    Posts
    50
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Re: Scaling

    I want to draw grid. I have minimal, maximal means, step. Should I specify QMatrix? How to do it? What should I do it?

    My previous code was:
    Qt Code:
    1. void QModeGraphics::drawGrid(QPainter *painter)
    2. {
    3. QRect rect(modesDisplay -> rect());
    4. if(!rect.isValid()) return;
    5.  
    6. QRect boundString;
    7. /// Отрисовка осей вдоль оси X
    8. for(int i=0; i<=settings.numXTicks; ++i)
    9. {
    10. int x = rect.left() + (i * (rect.width() - 1) / settings.numXTicks);
    11. double label = (settings.minX >= 0) ?
    12. settings.minX + (i * settings.spanX() / settings.numXTicks)
    13. : settings.maxX - (i * settings.spanX() / settings.numXTicks);
    14. QString s_label = GraphicDisplay::round(label);
    15.  
    16. painter -> setPen(Qt::black);
    17. painter -> drawLine(x, rect.top(), x, rect.bottom());
    18. if(i != settings.numXTicks)
    19. {
    20. int flags = Qt::AlignHCenter | Qt::AlignTop;
    21. boundString = painter -> boundingRect(boundString, flags, s_label);
    22. painter -> drawText(x - (boundString.width() + 5), rect.bottom() - (boundString.height() + 5),
    23. boundString.width(), boundString.height(), flags, s_label);
    24. }
    25. }
    26. if(mode != NULL)
    27. {
    28. int flags = Qt::AlignCenter;
    29. boundString = painter -> boundingRect(boundString, flags, mode -> x_param.param_name);
    30. painter -> drawText(rect.right() - boundString.width(), rect.bottom() - 2 * boundString.height(),
    31. mode -> x_param.param_name);
    32. }
    33. /// Отрисовка осей вдоль оси Y
    34. for(int j=0; j<=settings.numYTicks; ++j)
    35. {
    36. int y = rect.bottom() - (j * (rect.height() - 1) / settings.numYTicks);
    37. double label = settings.minY + (j * settings.spanY() / settings.numYTicks);
    38. QString s_label = GraphicDisplay::round(label);
    39.  
    40. painter -> setPen(Qt::black);
    41. painter -> drawLine(rect.left(), y, rect.right(), y);
    42. if(j != settings.numYTicks)
    43. {
    44. int flags = Qt::AlignRight | Qt::AlignTop;
    45. boundString = painter -> boundingRect(boundString, flags, s_label);
    46. painter -> drawText(rect.left() + 7, y - boundString.height(),
    47. boundString.width(), boundString.height(), flags, s_label);
    48. }
    49. }
    50. if(mode != NULL)
    51. {
    52. int flags = Qt::AlignCenter;
    53. boundString = painter -> boundingRect(boundString, flags, mode -> y_param.param_name);
    54. painter -> drawText(rect.left() + 7, rect.top() + boundString.height(),
    55. mode -> y_param.param_name);
    56. }
    57. painter -> drawRect(rect.adjusted(0, 0, -1, -1));
    58. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jun 2008
    Location
    Saint-Petersburg
    Posts
    50
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Re: Scaling

    Help me, please! I don't know how to draw the grid that is scale with graphic! Don't ignore my posts, please!

  8. #8
    Join Date
    Dec 2006
    Posts
    849
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    6
    Thanked 163 Times in 151 Posts

    Default Re: Scaling

    Well...

    first:
    * obviously I can't compile that example (not self contained)
    * I figure from your comment that this is working code, probable Qt3 based, right?
    * (I don't understand russian comments in kyrillian fonts, btw ;-)

    You should tell us what you want to do, what is your problem.
    From looking at your code, I would say that the same is possible in Qt4.
    (Why) do you want to change it?
    Is something not working/compiling?


    You only have to specify a matrix if you want to apply an affine transformation on the draw stuff. Scaling would be an example.
    So: if your problem is (only) that the grid is drawn in the wrong size, then yes: apply a scaling matrix to the painter.
    (Perhaps it would be in order to save() it first, and restore() it later.)

    HTH

  9. #9
    Join Date
    Jun 2008
    Location
    Saint-Petersburg
    Posts
    50
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Re: Scaling

    Well.....
    My problem is seen so: I don't know how it is possible in Qt4! What do I can with means of step, min and max values? What element in Qt account for it? I want to draw grid and graphic by Qt and not manually!

    My previous code worked but it didn't scale right! I solved write this code by management Qt!
    Sorry with my english! I say with difficulties and lexicographer! So my native language is russian!
    Last edited by AD; 19th June 2008 at 09:16.

  10. #10
    Join Date
    Dec 2006
    Posts
    849
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    6
    Thanked 163 Times in 151 Posts

    Default Re: Scaling

    As far as I know, there is no built-in stuff for drawing grids.
    You have to do it manually, i.e. code it yourself.

    But then, your code seems to be for drawing a grid...
    isn't it working?

  11. #11
    Join Date
    Jun 2008
    Location
    Saint-Petersburg
    Posts
    50
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Re: Scaling

    But.... Why I haven't Qt means?
    In my manual code I don't know how to do right scaling!
    My graphic stretched but it didn't near/move away! I don't know right algorithm scaling!

    P.S. May I turn to Qt built-in stuff?

Similar Threads

  1. Scaling Painter without scaling the coordinate sytem
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 7th January 2008, 21:30
  2. QPixmap scaling question
    By eric in forum Qt Programming
    Replies: 6
    Last Post: 20th November 2007, 17:40
  3. Ignoring scaling graphics view/scale
    By maverick_pol in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 17:44
  4. Pixmap scaling
    By yellowmat in forum Newbie
    Replies: 3
    Last Post: 4th January 2007, 16:01
  5. Replies: 12
    Last Post: 25th May 2006, 21:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.