Форум сайта python.su
Подскажите пожалуйста, ни как не могу догадаться как это сделать
from PyQt4 import QtGui class Board(QtGui.QWidget): def __init__(self): super(Board, self).__init__() self.all_notification = [] self.scroll_layout = QtGui.QVBoxLayout() self.scroll_widget = QtGui.QWidget() self.scroll_widget.setLayout(self.scroll_layout) self.scroll_area = QtGui.QScrollArea() self.scroll_area.setWidgetResizable(True) self.scroll_area.setWidget(self.scroll_widget) self.main_layout = QtGui.QVBoxLayout() self.main_layout.addWidget(self.scroll_area) self.setLayout(self.main_layout) self.default_label = QtGui.QLabel( '{}Уведомлений нет{}'.format(' ' * 14, ' ' * 14) ) self.scroll_layout.addWidget(self.default_label) self.scroll_layout.addStretch(0) self.all_notification.append(self.default_label) def add_notification(self, massage): self.all_notification[0].hide() notification = QtGui.QLabel(massage) self.scroll_layout.addWidget(notification) self.all_notification.append(notification) self._remove_stretch() self.scroll_layout.addStretch(0) def _remove_stretch(self): for i in reversed(range(self.scroll_layout.count())): item = self.scroll_layout.itemAt(i) if isinstance(item, QtGui.QSpacerItem): self.scroll_layout.removeItem(item) return app = QtGui.QApplication([]) w = QtGui.QWidget() l = QtGui.QHBoxLayout() w.setLayout(l) but = QtGui.QPushButton('Добавить сообщение') l.addWidget(but) b = Board() l.addWidget(b) but.clicked.connect(lambda: b.add_notification('wefew' * (b.scroll_layout.count() + 2))) w.show() app.exec_()
Отредактировано dima2881 (Март 22, 2016 21:48:15)
Офлайн