我需要删除屏幕上用红线(左侧)指示的缩进。
如何实施?
我尝试使用setSpacing
,但没有用。
此外,如果可以的话,很高兴知道如何删除小部件周围的白色选择框。(截图 2)
利润中心:
import sys
from PySide6 import QtWidgets, QtGui
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QLabel, QLayout, QSizePolicy,
QSpacerItem, QVBoxLayout, QWidget, QMainWindow, QListView, QAbstractItemView,
QListWidget, QFrame, QGridLayout)
class Ui_Form(object):
def setupUi(self, Form):
if not Form.objectName():
Form.setObjectName(u"Form")
Form.resize(179, 305)
Form.setMinimumSize(QSize(179, 0))
Form.setCursor(QCursor(Qt.PointingHandCursor))
Form.setStyleSheet(u"background-color: rgb(37, 41, 49)")
self.verticalLayout = QVBoxLayout(Form)
self.verticalLayout.setSpacing(2)
self.verticalLayout.setObjectName(u"verticalLayout")
self.verticalLayout.setSizeConstraint(QLayout.SetFixedSize)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.imagelabel = QLabel(Form)
self.imagelabel.setObjectName(u"imagelabel")
self.imagelabel.setMinimumSize(QSize(179, 256))
self.imagelabel.setMaximumSize(QSize(179, 256))
self.verticalLayout.addWidget(self.imagelabel)
self.nameru = QLabel(Form)
self.nameru.setObjectName(u"nameru")
self.nameru.setMaximumSize(QSize(16777215, 50))
font = QFont()
font.setFamilies([u"Segoe UI Black"])
font.setPointSize(10)
self.nameru.setFont(font)
self.nameru.setStyleSheet(u"color: rgb(241, 241, 241);\n"
"font-size: 10pt;\n"
"font-family: Segoe UI Black\n"
"")
self.nameru.setAlignment(Qt.AlignCenter)
self.nameru.setWordWrap(True)
self.verticalLayout.addWidget(self.nameru)
self.nameen = QLabel(Form)
self.nameen.setObjectName(u"nameen")
self.nameen.setMaximumSize(QSize(16777215, 30))
font1 = QFont()
font1.setFamilies([u"Segoe UI"])
font1.setPointSize(8)
self.nameen.setFont(font1)
self.nameen.setStyleSheet(u"color: #626a76;\n"
"font-size: 8pt;\n"
"font-family: Segoe UI\n"
"")
self.nameen.setAlignment(Qt.AlignCenter)
self.nameen.setWordWrap(True)
self.verticalLayout.addWidget(self.nameen)
self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
self.verticalLayout.addItem(self.verticalSpacer)
self.retranslateUi(Form)
QMetaObject.connectSlotsByName(Form)
# setupUi
def retranslateUi(self, Form):
Form.setWindowTitle(QCoreApplication.translate("Form", u"Form", None))
self.imagelabel.setText("")
self.nameru.setText(QCoreApplication.translate("Form", u"TEST", None))
self.nameen.setText(QCoreApplication.translate("Form", u"TEST:\n"
"Beiketushen", None))
class LinkedWidget(QtWidgets.QWidget, Ui_Form):
def __init__(self, parent=None):
super(LinkedWidget, self).__init__(parent)
self.setupUi(self)
self.imagedata = None
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
if not MainWindow.objectName():
MainWindow.setObjectName(u"MainWindow")
MainWindow.resize(864, 346)
MainWindow.setStyleSheet(u"background-color: rgb(37, 41, 49)")
self.centralwidget = QWidget(MainWindow)
self.centralwidget.setObjectName(u"centralwidget")
self.gridLayout = QGridLayout(self.centralwidget)
self.gridLayout.setObjectName(u"gridLayout")
self.linkedframe = QFrame(self.centralwidget)
self.linkedframe.setObjectName(u"linkedframe")
self.linkedframe.setMinimumSize(QSize(0, 50))
self.linkedframe.setFrameShape(QFrame.StyledPanel)
self.linkedframe.setFrameShadow(QFrame.Raised)
self.verticalLayout_23 = QVBoxLayout(self.linkedframe)
self.verticalLayout_23.setSpacing(0)
self.verticalLayout_23.setObjectName(u"verticalLayout_23")
self.verticalLayout_23.setContentsMargins(0, 0, 0, 0)
self.linkedlabel = QLabel(self.linkedframe)
self.linkedlabel.setObjectName(u"linkedlabel")
self.linkedlabel.setMinimumSize(QSize(0, 30))
self.linkedlabel.setMaximumSize(QSize(16777215, 30))
self.linkedlabel.setStyleSheet(u"color: rgb(241, 241, 241);\n"
"font-size: 14pt;\n"
"font-family: Segoe UI Black\n"
"")
self.verticalLayout_23.addWidget(self.linkedlabel)
self.linkedlistwidget = QListWidget(self.linkedframe)
self.linkedlistwidget.setObjectName(u"linkedlistwidget")
self.linkedlistwidget.setMinimumSize(QSize(0, 168))
self.linkedlistwidget.setLayoutDirection(Qt.LeftToRight)
self.linkedlistwidget.setAutoFillBackground(True)
self.linkedlistwidget.setStyleSheet(u"QListWidget{\n"
" padding: 5px;\n"
"}\n"
"QListWidget::item{\n"
" margin: 5px;\n"
" background-color: transparent; \n"
" border: 0px;\n"
" padding-left: 1px;\n"
"}\n"
"QListWidget::item:selected{\n"
"background-color: transparent;\n"
"}\n"
"QListWidget::item:hover{\n"
" background-color: transparent; \n"
"}")
self.linkedlistwidget.setFrameShape(QFrame.Panel)
self.linkedlistwidget.setDragEnabled(False)
self.linkedlistwidget.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
self.linkedlistwidget.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)
self.linkedlistwidget.setMovement(QListView.Static)
self.linkedlistwidget.setFlow(QListView.LeftToRight)
self.linkedlistwidget.setProperty("isWrapping", True)
self.linkedlistwidget.setResizeMode(QListView.Fixed)
self.linkedlistwidget.setLayoutMode(QListView.SinglePass)
self.linkedlistwidget.setSpacing(0)
self.linkedlistwidget.setViewMode(QListView.ListMode)
self.linkedlistwidget.setWordWrap(True)
self.linkedlistwidget.setSelectionRectVisible(False)
self.verticalLayout_23.addWidget(self.linkedlistwidget)
self.gridLayout.addWidget(self.linkedframe, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QMetaObject.connectSlotsByName(MainWindow)
# setupUi
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None))
self.linkedlabel.setText(QCoreApplication.translate("MainWindow", u"\u0421\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0435", None))
# retranslateUi
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setupUi(self)
self.linkedlistwidget.setSpacing(0)
for i in range(0, 5):
linkedwidget = LinkedWidget()
linkedwidget.nameru.setText("TEST")
linkedwidget.nameen.setText("TEST")
movie = QtGui.QMovie("loading.gif") # можете заменить другой гифкой или чем либо ещё
size = QSize(179, 256)
movie.setScaledSize(size)
linkedwidget.imagelabel.setMovie(movie)
movie.start()
item = QtWidgets.QListWidgetItem(self.linkedlistwidget)
item.setSizeHint(linkedwidget.sizeHint())
self.linkedlistwidget.addItem(item)
self.linkedlistwidget.setItemWidget(item, linkedwidget)
self.linkedlistwidget.setMinimumSize(QSize(0, item.sizeHint().height()))
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())