QTableView Zoom In/Out
Asked Answered
C

2

6

I'm trying to create a QTableView that can be zoomed in and out like in Excel.
A similar question was asked here: Zooming function on a QWidget

However, I'm subclassing the QTableView in PyQt and not C so reimplementing the entire PaintEvent method is a bit evolved. The source code for that is a bit complex: https://qt.gitorious.org/qt/tiittane-qt/source/bdd4a9149789f60974603e1f7621d51378f0a108:src/gui/itemviews/qtableview.cpp#L1282

I'm looking to see if there are any other viable options to have a zoom able TableView. My first attempt was by setting the font size then realized each column and row widths would have to scale as well which can become slow. Then realized changing the font would change the print. It didn't seems like an elegant solution. Changing the scale of the painter before painting seems like the more elegant solution but would have to re-implement and translate quite a bit of code to python to do so. I'm wondering if there are any other hooks to get this done.

Thanks

Convey answered 10/4, 2014 at 20:42 Comment(3)
did you have any success with this in the end? could you share the technique you settled on? thanks!Casualty
In the end the task was moved down in priority significantly where didn't work on it any more. At some point I'll revisit this but don't know when. There are some complexities and odd behaviors with using the Graphics Scene so I'm not sure if it's going to be any easier than reimplementing the paint method in the endConvey
I asked about this a couple of days ago, my search skillz are bad I guess...https://mcmap.net/q/1916909/-zooming-a-view-in-pyqt. I think I may end up just literally changing the font size and then resizing to content, which sucks, but oh well...Acetylcholine
S
2

If you can use QTableWidget instead then you can create a QGraphicsScene and add it to that. Then you easily control the scale of the widget within.

If you want vertical and horizontal headers always visible I think you will have to turn off the table's scrollbars (which would end up zoomed, probably not what you want anyways) and have the scrollbars part of the panel that contains the graphics scene (probably panel would be a QAbstractScrollArea with 4 cells in layout: one cell for scene, one for horiz scrollbar, one for vert scrollbar, and one for the corner maybe empty), and connect them to the table's scroll behavior.

Sanson answered 11/4, 2014 at 22:21 Comment(1)
That sounds like an excellent idea. I've been having trouble implementing it as the scroll bars seem to be an with issue keeping the Horizontal and Vertical headers visible scrolling with Graphics View.Convey
A
0

There is no built-in method to zoom on a view.

The simplest way to separate the size of the font on the screen, versus the size of the font saved or printed, is to basically have two fonts. One to be displayed on the screen you can call 'zoom', versus the other to be saved/printed and call that 'font size'.

Note this answer is cut and pasted from the same question: Zooming a view in PyQt?

Acetylcholine answered 14/6, 2015 at 19:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.