gpt4 book ai didi

python - QTextEdit 在调整大小时不显示水平滚动条

转载 作者:太空宇宙 更新时间:2023-11-04 10:32:00 27 4
gpt4 key购买 nike

[已解决]我想设置 QTextEdit 文档的大小(比如 8.5 x 11 或 3 x 5)。如果用户缩小 View ,则应该出现水平滚动条。当用户缩小 View 时,我找不到停止换行的设置。如果我完全停止换行,则会忽略所有页面大小设置。

#!/usr/bin/python 
#Python version: 3.4.1
#Pyside.__version__ 1.2.2
#PySide.__version_info__ (1, 2, 2, 'final', 0)
#PySide.QtCore.__version__ 4.8.5
#PySide.QtCore.__version_info__ (4, 8, 5)
#PySide.QtCore.qVersion() 4.8.5
# -*- coding: utf-8 -*-
"""
Horizontal Scrollbar test
"""
import sys, os
from PySide.QtCore import QSizeF
from PySide.QtGui import (QApplication, QTextEdit, QTextOption)

class myTextEdit(QTextEdit):
def __init__(self, parent=None):
super(myTextEdit, self).__init__(parent)
self.parent = parent

#FixedWidth disables re-size - NO H-scrollbar will appear
# self.setFixedWidth(500)

#LineWrapMode sets a Maximum line width for wrap, yet
#re-sizing the view wraps text before maximum - NO H-scrollbar appear
self.setLineWrapMode(QTextEdit.FixedColumnWidth)
self.setLineWrapColumnOrWidth(80)

#PageSize sets a Maximum for wrap (same as above) NO H-scrollbar
# pageSize = QSizeF()
# pageSize.setWidth(80)
# self.document().setPageSize(pageSize)

#NoWrap disables all above code. H-bar will show, but line never wraps.
# self.setWordWrapMode(QTextOption.NoWrap)

if __name__ == "__main__":
app = QApplication(sys.argv)
myWidget = myTextEdit()

myWidget.show()
sys.exit(app.exec_())

最佳答案

将 linewrapmode 设置为 FixedPixelWidth 实际上会执行您想要的操作,即出现水平滚动条并且线条在固定位置换行。我不知道为什么 FixedColumnWidth 在您的示例(以及此处)中没有给出类似的结果。

例子:

from PySide import QtGui, QtCore

app = QtGui.QApplication([])
window = QtGui.QWidget()
layout = QtGui.QVBoxLayout(window)
edit = QtGui.QTextEdit('jfdh afdhgfkjg fdnvfh vklkfjvkflj lddkl ljklfjkl jvkldjfkvljfgvjldf ll dl dljvklj ljljlbl llkb jbgl')
edit.setLineWrapColumnOrWidth(200)
edit.setLineWrapMode(QtGui.QTextEdit.FixedPixelWidth)
layout.addWidget(edit)
window.show()
app.exec_()

关于python - QTextEdit 在调整大小时不显示水平滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25839669/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com