We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class LabelListItemWidget(QWidget): def __init__(self, label: str, color: QColor, parent=None): super().__init__(parent=parent) self.hly = QHBoxLayout(self) self.hly.setContentsMargins(0, 0, 0, 0) self.cb_label_status = ColorPickerButton(color, "") self.cb_label_status.setFixedSize(16, 16) self.hly.addWidget(self.cb_label_status) self.hly.addWidget(BodyLabel(text=label)) self.label = label def get_label(self): return self.label class AnnotationEnsureMessageBox(MessageBoxBase): """ Custom message box """ def __init__(self, labels_color: dict, parent=None): super().__init__(parent) self.title_label = StrongBodyLabel(self.tr("Select the label"), self) self.le_label = LineEdit() self.list_widget = ListWidget() # 将组件添加到布局中 self.viewLayout.addWidget(self.title_label) self.viewLayout.addWidget(self.le_label) self.viewLayout.addWidget(self.list_widget) # self.widget.setFixedSize(300, 200) self.set_labels(labels_color) self.list_widget.itemClicked.connect(self.on_label_item_clicked) def set_labels(self, labels_color: dict): self.list_widget.clear() for label, color in labels_color.items(): item = QListWidgetItem() item.setSizeHint(QSize(item.sizeHint().width(), 100)) self.list_widget.addItem(item) label_item = LabelListItemWidget(label, color) self.list_widget.setItemWidget(item, label_item) labels = list(labels_color.keys()) if len(labels) > 0: self.list_widget.setCurrentIndex(self.list_widget.model().index(0, 0)) self.le_label.setText(labels[0]) def on_label_item_clicked(self, item: QListWidgetItem): widget = self.list_widget.itemWidget(item) if isinstance(widget, LabelListItemWidget): self.le_label.setText(widget.get_label()) def get_label(self): return self.le_label.text()
在使用核心代码:
item = QListWidgetItem() item.setSizeHint(QSize(item.sizeHint().width(), 100)) self.list_widget.addItem(item) label_item = LabelListItemWidget(label, color) self.list_widget.setItemWidget(item, label_item)
在添加item时,最后一个item的样式对不齐,并且在鼠标hover时好像被自定义的widget拦截了,hover的高亮出现异常,每一个item的行间距是否可以修改?
WIndows11 23H2
python 3.10 64bit
Pyside6.7.2
v1.6.0
只要添加自定义widget item就会出现
The text was updated successfully, but these errors were encountered:
这个组件只改了样式,对齐的问题和你的代码有关系
Sorry, something went wrong.
这个组件只改了样式,对齐的问题和你的代码有关系 只有列表的最后一项没对齐,前面几项时对齐的,你看那个gif中labels里面
我试了一下,只改写stylesheet,对齐问题就不存在了。应该是一些Item委托导致的问题,您可以随便找个例子尝试一下,只需要 self.list_widget.setItemWidget(item, label_item)就会存在这个问题
self.list_widget.setItemWidget(item, label_item)
item = QListWidgetItem() item.setSizeHint(QSize(item.sizeHint().width(), 100))
setSizeHint这里错误了,setSizeHint里面应该是实际的widget的size。 应该是 item.setSizeHint(widget.sizeHint()) widget为你实际的控件,否则的话item的大小是有问题的
No branches or pull requests
What happened?
在使用核心代码:
在添加item时,最后一个item的样式对不齐,并且在鼠标hover时好像被自定义的widget拦截了,hover的高亮出现异常,每一个item的行间距是否可以修改?
Operation System
WIndows11 23H2
Python Version
python 3.10 64bit
PyQt/PySide Version
Pyside6.7.2
PyQt/PySide-Fluent-Widgets Version
v1.6.0
How to Reproduce?
只要添加自定义widget item就会出现
Minimum code
The text was updated successfully, but these errors were encountered: