S
S
SangreSan2020-04-03 20:03:39
Python
SangreSan, 2020-04-03 20:03:39

How to insert a widget into a widget?

Good afternoon. It is necessary to implement the interface, as in the picture:

5e876b3276705588518012.jpeg

As you can see, it has already been implemented. Implemented as follows. There is a main element QListWidget. It has a QVBoxLayout assigned to it. 3 elements are inserted into QVBoxLayout: QHBoxLayout, Spacer(placeholder) and one more QHBoxLayout. The top QHBoxLayout has a placeholder on the left and a QLineEdit on the right (search, see image). In the lower QHBoxLayout, it's the same, but instead of a search, there is a button with a "+". The code itself (obj - QListWidget):

def _setupViewWidget(self, obj):
        """Конфигурация виджета для вставки в него элементов:
 
        1. Кнопка "Добавить" в нижний правый угол;
        2. строка поиска в правый верхний угол.
 
        Args:
            obj (:obj:`PyQt5.QtWidgets.QWidget`):
                виджет для настройки.
        """
 
        self.list_layout = QtWidgets.QVBoxLayout(obj)
        self.upper_spacer = QtWidgets.QSpacerItem(
            10, 10,
            QtWidgets.QSizePolicy.Minimum,
            QtWidgets.QSizePolicy.Expanding)
 
        self.list_layout.addItem(self.upper_spacer)
        self.bottom_layout = QtWidgets.QHBoxLayout()
 
        self.list_layout.addLayout(self.bottom_layout)
        self.add_button = QtWidgets.QPushButton("+")
 
        self.horizont_spacer = QtWidgets.QSpacerItem(
            10, 10,
            QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Minimum)
        self.bottom_layout.addItem(self.horizont_spacer)
        self.bottom_layout.addWidget(self.add_button)
 
        self.top_layout = QtWidgets.QHBoxLayout()
        self.search_line = QtWidgets.QLineEdit('Поиск')
        self.horizont_spacer_2 = QtWidgets.QSpacerItem(
            10, 10,
            QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Minimum)
        self.top_layout.addItem(self.horizont_spacer_2)
        self.top_layout.addWidget(self.search_line)
        self.top_layout.setStretch(0, 2)
        self.top_layout.setStretch(1, 1)
 
        self.list_layout.insertLayout(0, self.top_layout)


When scrolling the list (QListWidget), there are graphical glitches (elements move out, see image). Question. Is it implemented "correctly"? If not, how to implement? If so, how to get rid of graphic glitches?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question