gpt4 book ai didi

python - 将 QTextEdit 添加到 QScrollArea

转载 作者:太空宇宙 更新时间:2023-11-04 02:31:21 25 4
gpt4 key购买 nike

我的 QTextEdit 区域中有一个文本 block ,但它对于该区域来说太大了。我尝试将 textArea 添加到 QScrollArea 以使我能够滚动浏览文本。我想知道我哪里出了问题,因为它似乎没有做任何事情。我想知道什么是正确的做法。这是我的代码和输出的堆栈跟踪。

# Import Statements
from PyQt5 import QtCore, QtGui, QtWidgets
from MainGuiWindow import Ui_MainWindow

# Main Class that holds User Interface Objects
class Ui_informationWindow(object):

# Function for Opening Main GUI window from login window by clicking login button
def openMainWindow(self):
self.window = QtWidgets.QMainWindow()
self.ui = Ui_MainWindow()
self.ui.setupUi(self.window)
loginWindow.hide()
self.window.show()

def setupUi(self, informationWindow):
informationWindow.setObjectName("User Information Window")
informationWindow.setFixedSize(393, 300)
self.centralwidget = QtWidgets.QWidget(informationWindow)
self.centralwidget.setObjectName("centralwidget")
informationWindow.setStyleSheet("background-color: Cornflowerblue")

# Proceed button
self.proceedButton = QtWidgets.QPushButton(self.centralwidget)
self.proceedButton.setGeometry(QtCore.QRect(280, 250, 101, 27))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.proceedButton.setFont(font)
self.proceedButton.setStyleSheet("background-color: Silver")
self.proceedButton.setObjectName("proceedButton")



# passwordTF
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(20, 10, 350, 230))
self.textEdit.setObjectName("informationTF")
informationWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(loginWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 393, 21))
self.menubar.setObjectName("menubar")
informationWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(informationWindow)
self.statusbar.setObjectName("statusbar")
self.textEdit.setStyleSheet("background-color: White")

# Set Scroll Area
self.textEdit.append("This is an information manual to guide users through the use of the software.")
self.textEdit.append("\n")
self.textEdit.append("To use this software, the user must first parse the data from each evidence item which will store the data in Microsoft Excel table format in an external directory")
self.textEdit.append("In turn, the corresponding report generation options will become available one by one to enable report generation for that piece of evidence.")
self.textEdit.append("\n")
self.textEdit.append("Once each report has been generated, the user can then view a single report for one piece of evidence or view a full report containing all parsed evidence.")
self.textEdit.append("\n")
self.textEdit.append("These reports, much like the parsed forensic data are stored in a Forensic Reports directory.")
self.textEdit.append("\n")
self.textEdit.append("Please press the Proceed button to begin using the software.")
self.textEdit.setFont(font)
self.textEdit.setEnabled(False)

# This is where I am trying to put the textEdit text into a scrollArea to make it scrollable
self.scrollArea = QtWidgets.QScrollArea()
self.textEdit.setVerticalScrollBar(self.textEdit)

informationWindow.setStatusBar(self.statusbar)


self.retranslateUi(informationWindow)
QtCore.QMetaObject.connectSlotsByName(informationWindow)

# Function that sets the text on all the UI Buttons
def retranslateUi(self, loginWindow):
_translate = QtCore.QCoreApplication.translate
loginWindow.setWindowTitle(_translate("informationWindow", "User Manual"))
self.proceedButton.setText(_translate("informationWindow", "Proceed"))

# Event Handling Code Section

# Event Handling to open Main GUI Window
self.proceedButton.clicked.connect(self.openMainWindow)


if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
loginWindow = QtWidgets.QMainWindow()
ui = Ui_informationWindow()
ui.setupUi(loginWindow)
loginWindow.show()
sys.exit(app.exec_())

堆栈跟踪

self.textEdit.setVerticalScrollBar(self.textEdit)
TypeError: QAbstractScrollArea.setVerticalScrollBar(QScrollBar): argument 1 has unexpected type 'QTextEdit'

最佳答案

QTextEdit 已经有一个 QScrollBar 所以你不应该添加任何,如果你想要文本不可编辑你应该使用 setReadOnly(True) 而不是 setEnabled(False)

# passwordTF
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
[...]
self.textEdit.setFont(font)
self.textEdit.setReadOnly(True)

关于python - 将 QTextEdit 添加到 QScrollArea,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49085620/

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