Results 1 to 13 of 13

Thread: Zoom a view?

  1. #1
    Join Date
    Jun 2014
    Posts
    98
    Thanks
    43
    Thanked 4 Times in 4 Posts
    Platforms
    Windows

    Default Zoom a view?

    I have a QTreeView of some text, displayed in a QMainWindow, and I want the user to be able to zoom on the view without having to change the font size in the view. Is this possible? Or would I have to embed the tree view in a QGraphicsScene?

    A post from Trolltech in 2007 said:
    Widgets cannot be scaled or rotated, but graphics items can.
    Is this still the case?

    Note this is a slightly edited version of a question I asked at Stack Overflow:
    http://stackoverflow.com/questions/3...a-view-in-pyqt

    Someone asked a similar question earlier:
    http://www.qtcentre.org/threads/3545...QT-programming
    Last edited by neuronet; 9th June 2015 at 20:31.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Zoom a vew?

    Quote Originally Posted by neuronet View Post
    I want the user to be able to zoom on the view without having to change the font size in the view
    Hmm... how exactly would this "zooming" work? Should all the text remain the same size ("not changing font size") or should the text grow with its quality worsened (one pixel of each glyph gets scaled to e.g. 4 pixels). Could you provide a mockup image of what you want?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2014
    Posts
    98
    Thanks
    43
    Thanked 4 Times in 4 Posts
    Platforms
    Windows

    Default Re: Zoom a vew?

    Quote Originally Posted by wysota View Post
    Hmm... how exactly would this "zooming" work? Should all the text remain the same size ("not changing font size") or should the text grow with its quality worsened (one pixel of each glyph gets scaled to e.g. 4 pixels). Could you provide a mockup image of what you want?
    I want the underlying font size to stay the same for printing or saving to PDF, but I want its appearance on the screen to change with some kind of interaction, such as a spinbox. I want high quality at higher magnification (so not like zooming an image where things get pixellated). Kind of like the following (except the one that appears bigger magnification should read 120%):

    fontScaling.png

    Open Office and MS Word both have this capacity. That is, there is a scrollbar at the bottom right that scales the appearance of the text (its size on the screen), but the underlying font size (point size) stays the same (e.g., for printing or saving the document). The quality is fine at high magnification. I was hoping for something like that with my tree view.
    Last edited by neuronet; 10th June 2015 at 18:17.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Zoom a vew?

    Quote Originally Posted by neuronet View Post
    I want the underlying font size to stay the same for printing or saving to PDF
    You want to print a widget? That's unusual.

    I want high quality at higher magnification (so not like zooming an image where things get pixellated).
    That's impossible to achieve without changing the size of the font

    Open Office and MS Word both have this capacity.
    No, they don't. The fact they tell you a particular font is set to 10pt doesn't mean they render it at 10pt. You can do exactly the same.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2014
    Posts
    98
    Thanks
    43
    Thanked 4 Times in 4 Posts
    Platforms
    Windows

    Default Re: Zoom a vew?

    Quote Originally Posted by wysota View Post
    No, they don't. The fact they tell you a particular font is set to 10pt doesn't mean they render it at 10pt. You can do exactly the same.
    Word and Office do exactly what I want. Whether they are doing it a certain way, or my terminology was perfect, is another question, but my question is how can I get my treeview to behave like that?

    You also wrote "You can do exactly the same." Yes, that's my question. Given the docs I've looked at and mentioned above, I am still not sure how, unless I somehow wrap my whole widget into a QGraphicsScene, which seems like overkill. Or unless the old trolltech doc I quoted is wrong.
    Last edited by neuronet; 11th June 2015 at 03:11.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Zoom a vew?

    Quote Originally Posted by neuronet View Post
    Word and Office do exactly what I want. Whether they are doing it a certain way, or my terminology was perfect, is another question, but my question is how can I get my treeview to behave like that?
    Adjust the font.

    unless I somehow wrap my whole widget into a QGraphicsScene
    This will not change a thing. You would not get the effect you wanted. While the font might look ok, all bitmaps will be upscaled.

    Qt Code:
    1. #include <QApplication>
    2. #include <QTreeView>
    3. #include <QFileSystemModel>
    4. #include <QGraphicsView>
    5. #include <QGraphicsScene>
    6. #include <QGraphicsProxyWidget>
    7.  
    8. int main(int argc, char **argv) {
    9. QApplication app(argc, argv);
    10. view.setScene(&scene);
    11.  
    12. QFileSystemModel model;
    13. model.setRootPath("/usr/share/icons");
    14. lv.setModel(&model);
    15. QGraphicsProxyWidget *w = scene.addWidget(&lv);
    16. w->setScale(4);
    17. view.show();
    18.  
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 

    scaledview.jpg

    If you want to have zoomable UI then indeed the simplest thing is to wrap it in graphics view but the result will be far different from text processor zoom functionality.
    Last edited by wysota; 11th June 2015 at 07:22.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    neuronet (11th June 2015)

  8. #7
    Join Date
    Jun 2014
    Posts
    98
    Thanks
    43
    Thanked 4 Times in 4 Posts
    Platforms
    Windows

    Default Re: Zoom a vew?

    Wysota: Your example is very helpful, I will convert to PySide and play with it, thank you.

    Quote Originally Posted by wysota View Post
    Adjust the font.
    That is not what word/open office are doing. The font can remain 10pt in the doc, but you can zoom it so it appears different on the screen. So at some level the underlying font size and the size on the screen are independently manipulated. Again, I apologize if my jargon is not perfect here (maybe there are two different font sizes or something so to discuss an "underlying font size" as if there is just one is inaccurate), but it is not some obscure esoteric thing I am after!

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Zoom a vew?

    Quote Originally Posted by neuronet View Post
    That is not what word/open office are doing. The font can remain 10pt in the doc, but you can zoom it so it appears different on the screen. So at some level the underlying font size and the size on the screen are independently manipulated.
    You seem to be missing the point. If you scale the document 10 times and you have formatting telling you the font is 10pt, maybe I will ruin your view on the world, but I have to tell you Word does not render that text with 10pt font but rather with 100pt one. And the cheater still tells you it is 10pt You should do the same, at 100% scale render with 10pt, at 200% render with 20pt and so on. That's what Qt does in my Graphics View example as well. It cannot do that with bitmaps though, that's why you get aliasing.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. The following user says thank you to wysota for this useful post:

    neuronet (11th June 2015)

  11. #9
    Join Date
    Jun 2014
    Posts
    98
    Thanks
    43
    Thanked 4 Times in 4 Posts
    Platforms
    Windows

    Default Re: Zoom a vew?

    Quote Originally Posted by wysota View Post
    You seem to be missing the point. If you scale the document 10 times and you have formatting telling you the font is 10pt, maybe I will ruin your view on the world, but I have to tell you Word does not render that text with 10pt font but rather with 100pt one. And the cheater still tells you it is 10pt You should do the same, at 100% scale render with 10pt, at 200% render with 20pt and so on. That's what Qt does in my Graphics View example as well. It cannot do that with bitmaps though, that's why you get aliasing.
    OK, I assume you are right on that front, but it will print as 10 point. So there are still two things that can be independently manipulated. That's what I'm after. I guess the thing to do is have two font spinboxes: one for appearance on screen, one for appearance on printer. The former I will call "zoom" and the latter I will call "font size".

    From what you've said, it seems that's what Word/Office are doing.
    Last edited by neuronet; 11th June 2015 at 16:49.

  12. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Zoom a vew?

    Quote Originally Posted by neuronet View Post
    OK, I assume you are right on that front, but it will print as 10 point. So there are still two things that can be independently manipulated. That's what I'm after. I guess the thing to do is have two font spinboxes: one for appearance on screen, one for appearance on printer. The former I will call "zoom" and the latter I will call "font size".
    Printing does not happen magically. Qt prints whatever you tell it to print. If you tell it to draw text with 10pt font, it will do just that. If you tell it to draw with 20pt font, it will do that too. If you tell it to draw on the screen with 24pt font and print on paper with 12pt font it will do that as well. It is you who decides what gets printed.

    Just look that Word does not send the exact copy of what you see on the screen to the printer. If you tell it to show unprintable characters, you will get them on screen but not on print. Printing "widgets" really does not make much sense, you should have a view on your data that looks good on a screen and a different "view" that will be sent to the printer. You will not get good output using the same view for both, even if only because of a resolution difference between the screen (usually less than 100dpi) and the printer (usually 600dpi or more). The same "widget" printed on such printer will be six times smaller than when rendered on your display. I don't think I would ever want to see a tree view (with borders, scrollbars and stuff) printed as a document.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #11
    Join Date
    Jun 2014
    Posts
    98
    Thanks
    43
    Thanked 4 Times in 4 Posts
    Platforms
    Windows

    Default Re: Zoom a vew?

    Quote Originally Posted by wysota View Post
    I don't think I would ever want to see a tree view (with borders, scrollbars and stuff) printed as a document.
    It's ugly, to be sure, but it works for my purposes right now.

  14. #12
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Zoom a vew?

    Then just flip-flop fonts when you print:

    Qt Code:
    1. // In your print method
    2.  
    3. QFont screenFont = myTree->font();
    4. QFont printFont = screenFont;
    5. printFont.setPointSize( 10 );
    6. myTree->setFont( printFont );
    7.  
    8. // Print it
    9.  
    10. myTree->setFont( screenFont );
    To copy to clipboard, switch view to plain text mode 

    You might have to force an update before you print, dunno.

  15. The following user says thank you to d_stranz for this useful post:

    neuronet (11th June 2015)

  16. #13
    Join Date
    Jun 2014
    Posts
    98
    Thanks
    43
    Thanked 4 Times in 4 Posts
    Platforms
    Windows

    Default Re: Zoom a vew?

    Quote Originally Posted by d_stranz View Post
    Then just flip-flop fonts when you print:

    Qt Code:
    1. // In your print method
    2.  
    3. QFont screenFont = myTree->font();
    4. QFont printFont = screenFont;
    5. printFont.setPointSize( 10 );
    6. myTree->setFont( printFont );
    7.  
    8. // Print it
    9.  
    10. myTree->setFont( screenFont );
    To copy to clipboard, switch view to plain text mode 

    You might have to force an update before you print, dunno.
    That seems exactly right.

Similar Threads

  1. Replies: 3
    Last Post: 11th March 2015, 03:21
  2. Change last zoom view
    By Sangfeust in forum Qwt
    Replies: 1
    Last Post: 4th February 2015, 16:41
  3. QWTPlot Zoom: cannot zoom negative value
    By jwieland in forum Qwt
    Replies: 0
    Last Post: 8th January 2010, 16:16
  4. Replies: 1
    Last Post: 16th November 2009, 05:25
  5. how to zoom out item in View/Scene
    By nileshsince1980 in forum Qt Programming
    Replies: 7
    Last Post: 28th December 2007, 10:24

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.