【发布时间】:2020-10-12 07:28:18
【问题描述】:
如何更正样式表中应用的QTextEdit 小部件的尖角?QTextEdit 的角落在 border 的边界内是目的。
# importing libraries
from PySide2.QtWidgets import *
from PySide2.QtGui import *
from PySide2.QtCore import *
import sys
class Scene(QGraphicsScene):
def __init__(self, _scene_width, _scene_height):
super(Scene, self).__init__()
self.setSceneRect(0, 0, _scene_width, _scene_height)
map_center = _scene_width / 2
te = QTextEdit()
te.setStyleSheet(" border-radius: 30px;background-clip: border; background-color: rgb(220, 220,220); color: rgb(113, 113, 113); font: 14pt Vazir; border:4px solid; border-color: rgb(255,95,95);")
te.insertPlainText("Test Text")
te.setGeometry(map_center, map_center, 100, 100)
self.addWidget(te)
class View(QGraphicsView):
def __init__(self, _scene_width, _scene_height):
super(View, self).__init__()
self.scale_factor = 1
self.scene_width = _scene_width
self.scene_height = _scene_height
scene = Scene(_scene_width, _scene_height)
self.setScene(scene)
self.showMaximized()
def main():
app = QApplication(sys.argv)
view = View(1000, 1000)
view.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
代码结果
【问题讨论】:
-
此文本编辑是添加到小部件 [布局] 还是顶级窗口?如果不是,您是否为其任何父小部件设置了样式表?
-
@musicamante 它被添加到
QGraphicsScene。没有。 -
您将小部件添加到 QGraphicsScene 的事实是您应该提到的一个重要方面。如果你使用
te.setAttribute(QtCore.Qt.WA_NoSystemBackground, True)会发生什么? -
@musicamante
te.setAttribute(QtCore.Qt.WA_NoSystemBackground, True)没有帮助;除了QTextEdit的文字之外的所有内容都消失了。我已更新问题以使其更易于测试。
标签: python pyqt5 border pyside2 qtextedit