D
D
danis_20142017-02-01 15:21:46
Python
danis_2014, 2017-02-01 15:21:46

How to add your widget in PyQt 5?

It is necessary to make a tape (as in VK). I decided to make the main widget and the widget for the post:

from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import sys

class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        box = QVBoxLayout(self)
        self.setLayout(box)
        self.setFixedSize(500, 600)
        self.move(300, 40)

        scroll = QScrollArea(self)
        box.addWidget(scroll)
        scrollContent = QWidget(scroll)
        scrollLayout = QVBoxLayout(scrollContent)
        scrollContent.setLayout(scrollLayout)

        for post in range(0, 100):
            scrollLayout.addWidget(Post())

        scroll.setWidget(scrollContent)

        self.show()

class Post(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('Post')
        self.resize(100, 100)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

But I get only this:
b43ee477338a4743a7acaacc097c09d7.png
How to make the extension widget visible?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
ghost_83, 2017-02-17
@ghost_83

https://pythonworld.ru/gui/pyqt5-customwidgets.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question