gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
QTreeView将一个节点拖动为另一个节点的子节点时会出现一个默认白框,如何消除这个白框
- User
QTreeView将一个节点拖动为另一个节点的子节点时会出现一个默认白框,如何消除这个白框
- Assistant
可以使用QTreeView的setStyleSheet方法来设置样式表,将默认的拖动边框的颜色设置为和背景颜色一样的颜色,这样就可以消除拖动时出现的白框。
下面是示例代码:
from PyQt5.QtWidgets import QApplication, QMainWindow, QTreeView, QFileSystemModel from PyQt5.QtGui import QColor, QPalette app = QApplication([]) win = QMainWindow() # 创建QTreeView和QFileSystemModel tree = QTreeView() model = QFileSystemModel() model.setRootPath("") tree.setModel(model) # 设置背景颜色为白色 palette = QPalette() palette.setColor(QPalette.Background, QColor(255, 255, 255)) tree.setPalette(palette) # 设置样式表,将拖动边框颜色设置为白色 style_sheet = """ QTreeView::item:!active { border: 1px solid white; } """ tree.setStyleSheet(style_sheet) win.setCentralWidget(tree) win.show() app.exec_()在这个示例中,我们将QTreeView的背景颜色设置为白色,然后使用样式表将拖动边框颜色设置为白色。这样,当我们拖动一个节点时,就不会出现白框了。
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.