Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6778161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:14:03+00:00 2026-05-26T16:14:03+00:00

Is it possible to scale (or zoom) a QTextEdit area? I believe I read

  • 0

Is it possible to scale (or “zoom”) a QTextEdit area? I believe I read that placing QTextEdit inside QLayout can allow for scaling of the QTextEdit area, though did not find how to implement it. Couple of options…

CTRL + Roll of Mouse Wheel
Running the code below, holding down the CTRL (control) key and rolling the mouse wheel, the event is captured and the text does scale (at least on Windows), however, as the text grows larger the wheel has to move further and further for very much effect, so one goal is to be able to modify that somehow, maybe some math to increase the increments to a greater degree on increases in the plus direction.

(The setReadOnly()’s below are because it would seem textEdit has to be ReadOnly(False) for the mouse event to be captured, then True to be able to scale during roll of the mouse wheel, so it is then set back to original state of False again on release of the CTRL key).

Toolbar Button Click
The other option is toolbar buttons for zoom in and out.
onZoomInClicked() is called.

Some current problems with the code below
1. It prints: QLayout: Attempting to add QLayout "" to MainWindow "", which already has a layout and I don’t have my head wrapped around that yet.
2. QtGui.QTextEdit(self.formLayout) instead of (self) to place the textEdit area inside the layout produces TypeError: 'PySide.QtGui.QTextEdit' called with wrong argument types
3. wheelEvent() could use some way to modify event.delta() maybe?
4. The toolbar button (text only) will currently run its def when clicked, however it only contains a print statement.

from PySide import QtGui, QtCore

class MainWindow(QtGui.QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)

        self.formLayout   = QtGui.QFormLayout(self)
        self.textEdit     = QtGui.QTextEdit(self)
        self.toolBar      = QtGui.QToolBar(self)
        self.actionZoomIn = QtGui.QAction(self)
        self.textEdit.setHtml('<font color=blue>Hello <b>world</b></font>')
        self.setCentralWidget(self.textEdit)
        self.addToolBar(self.toolBar)
        self.toolBar.addAction(self.actionZoomIn)
        self.actionZoomIn.setText('Zoom In')
        self.actionZoomIn.connect(self.actionZoomIn,
            QtCore.SIGNAL('triggered()'), self.onZoomInClicked)

    def onZoomInClicked(self):
        print "onZoomInClicked(self) needs code"

    def wheelEvent(self, event):
        print "wheelEvent() captured"
        if (event.modifiers() & QtCore.Qt.ControlModifier):
            self.textEdit.setReadOnly(True)

            event.accept()            

    def keyReleaseEvent(self, evt):
        if evt.key() == QtCore.Qt.Key_Control:
            self.textEdit.setReadOnly(False)

if __name__ == '__main__':
    app   = QtGui.QApplication([])
    frame = MainWindow()
    frame.show()
    app.exec_()

I’ve been grappling with this for days so would be great to have the more customizable QTextEdit scale/zoom working if it is even possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:14:04+00:00Added an answer on May 26, 2026 at 4:14 pm

    The two error messages can be expained as follows:

    1. The QMainWidget automatically gets a layout, so the QFormLayout is redundant. If you want to add a layout, create a QWidget to be the central widget and make it the parent of the new layout. Other widgets can then be added to that new layout.
    2. The parent of a QWidget subclass must itself be QWidget subclass, which QFormLayout isn’t.

    I’ve modified your example so that it does most of what you asked for. Note that QTextEdit.zoomIn and QTextEdit.zoomOut both take a range argument for controlling the degree of zoom.

    from PySide import QtGui, QtCore
    
    class MainWindow(QtGui.QMainWindow):
        def __init__(self, parent=None):
            super(MainWindow, self).__init__(parent)
            self.textEdit = Editor(self)
            self.toolBar = QtGui.QToolBar(self)
            self.actionZoomIn = QtGui.QAction('Zoom In', self)
            self.actionZoomOut = QtGui.QAction('Zoom Out', self)
            self.textEdit.setHtml('<font color=blue>Hello <b>world</b></font>')
            self.setCentralWidget(self.textEdit)
            self.addToolBar(self.toolBar)
            self.toolBar.addAction(self.actionZoomIn)
            self.toolBar.addAction(self.actionZoomOut)
            self.actionZoomIn.triggered.connect(self.onZoomInClicked)
            self.actionZoomOut.triggered.connect(self.onZoomOutClicked)
    
        def onZoomInClicked(self):
            self.textEdit.zoom(+1)
    
        def onZoomOutClicked(self):
            self.textEdit.zoom(-1)
    
    class Editor(QtGui.QTextEdit):
        def __init__(self, parent=None):
            super(Editor, self).__init__(parent)
    
        def zoom(self, delta):
            if delta < 0:
                self.zoomOut(1)
            elif delta > 0:
                self.zoomIn(5)
    
        def wheelEvent(self, event):
            if (event.modifiers() & QtCore.Qt.ControlModifier):
                self.zoom(event.delta())
            else:
                QtGui.QTextEdit.wheelEvent(self, event)
    
    if __name__ == '__main__':
    
        import sys
        app = QtGui.QApplication(sys.argv)
        window = MainWindow()
        window.show()
        app.exec_()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Zoom in on a point (using scale and translate) I want to
Why fourier transform(dft) is not possible on color images? Why only on gray scale
Is it possible to add an image overlay to a google map that scales
Possible Duplicate: C++ templates that accept only certain types For example, if we want
I am looking for ways to zoom in a Java Swing application. That means
Is it possible to change the scaling factor of a UIScrollView? What I mean
Is it possible to proportionally scale a div like an img using only CSS?
I'm wondering if it possible to actually change a UIViews scale value without actually
Is it possible to scale ImageView only in particular part? I have a ImageView
I know that I can use cover or contain value for the 'background-size' property,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.