English 中文(简体)
字体变化后,QTextEdit的动物园林没有影响
原标题:No effect from ZoomIn in QTextEdit after font size change

这部法典用一个工具路障和一个QTextEdit地区运行一个很小的窗口。

如果你强调香蕉和改变老体大小,那么使用 tool子或CTRL+湿轮只会使 app体变。 任何人都知道为什么?

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.addToolBar(self.toolBar)
        self.setCentralWidget(self.textEdit)
        self.textEdit.setHtml( <font color=blue>apples bananas</font> )

        # Zoom
        self.actionZoomIn  = QtGui.QAction( Zoom In ,  self)
        self.actionZoomOut = QtGui.QAction( Zoom Out , self)
        self.toolBar.addAction(self.actionZoomIn)
        self.toolBar.addAction(self.actionZoomOut)
        self.actionZoomIn.triggered.connect(self.onZoomInClicked)
        self.actionZoomOut.triggered.connect(self.onZoomOutClicked)

        # Font Size
        self.comboSize = QtGui.QComboBox(self.toolBar)
        self.toolBar.addWidget(self.comboSize)
        self.comboSize.addItem( 0 )
        self.comboSize.addItem( 10 )
        self.comboSize.addItem( 18 )
        self.comboSize.addItem( 30 )
        self.comboSize.addItem( 48 )
        self.comboSize.setCurrentIndex(1)
        self.comboSize.activated[str].connect(self.textSize)

    def textSize(self, pointSize):
        pointSize = int(pointSize)
        if pointSize > 0:
            fmt = QtGui.QTextCharFormat()
            fmt.setFontPointSize(pointSize)
            self.mergeFormatOnWordOrSelection(fmt)

    def mergeFormatOnWordOrSelection(self, format):
        cursor = self.textEdit.textCursor()
        if not cursor.hasSelection():
            cursor.select(QtGui.QTextCursor.WordUnderCursor)

        cursor.mergeCharFormat(format)
        self.textEdit.mergeCurrentCharFormat(format)

    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)
        self.zoomValue = 0

    def zoom(self, delta):
        zoomIncrement = 3

        if delta < 0:
            zoomIncrement = 0 - zoomIncrement

        self.zoomIn(zoomIncrement)
        self.zoomValue = self.zoomValue + zoomIncrement

        print "self.zoomValue", self.zoomValue

    def wheelEvent(self, event):
        if (event.modifiers() & QtCore.Qt.ControlModifier):
            self.zoom(event.delta())

if __name__ ==  __main__ :
    app = QtGui.QApplication([])
    window = MainWindow()
    window.resize(400, 180)
    window.show()
    app.exec_()
最佳回答

<代码>QTextEdit.zoomIn/Out的违约执行 只是修改文本编辑的基字体的<代码>。

改用字体尺寸的计算方法是在<条码>中选用字标/代码>,并使用线标,将<条码>font-size 财产定值。 这意味着,在案文编辑之后,只有未改动的案文才会受到影响。

通过使用相对体积来解决这一问题。 然而,它只看一个温和的子集:csss nature得到了支持,因此它唯一可能设定诸如smalllarge等不准确的数值。

可以通过作出以下修改来实施:

    # Font Size
    self.comboSize = QtGui.QComboBox(self.toolBar)
    self.toolBar.addWidget(self.comboSize)
    self.comboSize.addItem( small )
    self.comboSize.addItem( medium )
    self.comboSize.addItem( large )
    self.comboSize.addItem( x-large )
    self.comboSize.addItem( xx-large )
    self.comboSize.setCurrentIndex(1)
    self.comboSize.activated[int].connect(self.textSize)

def textSize(self, size):
    fmt = QtGui.QTextCharFormat()
    fmt.setProperty(QtGui.QTextFormat.FontSizeAdjustment, size - 1)
    self.mergeFormatOnWordOrSelection(fmt)
问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签