本文介紹了PyQt5標簽被切斷的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
當我運行這個程序時,我的部分標簽被切斷了.有沒有什么辦法解決這一問題?我猜它與 setFont 有關,因為當我刪除 l1.setFont 時,所有文本都會顯示.如果可能,請列出不會過多改變 GUI 的解決方案.
When I run this program, parts of my label gets cut off. Is there any way to fix this? I'm guessing it has to do with setFont, because when I remove l1.setFont all the text shows. If possible, please list solutions that doesn't alter the GUI too much.
import sys
from PyQt5 import QtGui, QtWidgets, QtCore, Qt
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
class App(QtWidgets.QMainWindow):
def __init__(self):
super(App, self).__init__()
self.setWindowTitle('Test GUI')
self.setWindowIcon(QtGui.QIcon('logo.png'))
self.setGeometry(800, 500, 500, 500)
self.ui()
def ui(self):
l1 = QtWidgets.QLabel(self)
l1.setText('Text')
l1.setFont(QtGui.QFont('Arial', 50))
l1.move(100, 100)
self.show()
def main():
app = QtWidgets.QApplication(sys.argv)
GUI = App()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
推薦答案
既然你改變了字體的大小,你必須調整字體的大小,你必須使用 adjustSize()
:
Since you have changed the size of the font you must adjust the size for that you must use adjustSize()
:
def ui(self):
l1 = QtWidgets.QLabel(self)
l1.setText('Text')
l1.setFont(QtGui.QFont('Arial', 50))
l1.adjustSize()
l1.move(100, 100)
self.show()
這篇關于PyQt5標簽被切斷的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!