0

I am trying to create a program that search for repeated files and add this repeated files in a Qt interface.

My idea in to search the repeated files and show this items in a scroll area.

The problem is that when I add items to the scroll area the items does not stay in the space i intend to be the scroll.

I tried to read many tutorials and helps, but I could not manage to make it works

Below I put my code:

To make it faster I am developing the in

__author__ = 'alvaro'

from PySide.QtGui import QWidget, QVBoxLayout, QLabel, QLineEdit, QApplication,QToolButton, QHBoxLayout,QCheckBox, QComboBox, QGridLayout,QScrollArea
from PySide.QtCore import QObject, SIGNAL
import sys

class MainDupFiles(QWidget):
    def __init__(self):
        super(MainDupFiles, self).__init__()
        self.interface()


    def interface(self):
        self.setMaximumHeight(500)
        self.vBoxTop = QVBoxLayout(self)
        self.inputLabel = QLabel("Digite aqui o caminho de pasta que deseja verificar arquivos repetidos")
        self.inputLine = QLineEdit()

        self.vBoxTop.addWidget(self.inputLabel)
        self.vBoxTop.addWidget(self.inputLine)
        self.vBoxTop.setContentsMargins(10,10,10,0)


        self.searchBtn = QToolButton()
        self.searchBtn.setText("Search")

        self.reportBtn = QToolButton()
        self.reportBtn.setText("Generate Report")

        self.deleteBtn = QToolButton()
        self.deleteBtn.setText("Delete Repeated Files")

        self.delAllCheckBox = QCheckBox("Delete All Files")
        self.delGroupCheckBox = QCheckBox("Delete This Group")

        self.groupCompoBox = QComboBox()
        self.groupCompoBox.addItem("Select the File name")
        self.groupCompoBox.setMinimumWidth(200)

        self.hWidget = QWidget(self)
        self.hBoxBtn = QHBoxLayout(self.hWidget)

        self.hBoxBtn.addWidget(self.searchBtn)
        self.hBoxBtn.addWidget(self.reportBtn)
        self.hBoxBtn.addWidget(self.deleteBtn)
        self.hBoxBtn.addWidget(self.groupCompoBox)
        self.hBoxBtn.addWidget(self.delGroupCheckBox)
        self.hBoxBtn.addWidget(self.delAllCheckBox)

        self.vBoxTop.addWidget(self.hWidget)

        QObject.connect(self.searchBtn, SIGNAL("clicked()"), self.addLines)

    def addLines(self):
        self.bottonWidget = QWidget()
        self.outputWidget = QWidget()

        self.outPutGrid = QGridLayout(self.outputWidget)
        for i in range(10):
            self.outPutGrid.addWidget(QLabel("TESTE"))

        self.scroll = QScrollArea(self.bottonWidget)
        self.scroll.setMinimumHeight(400)
        self.outPutGrid.addWidget(self.bottonWidget)
        self.scroll.setWidget(self.outputWidget)
        self.vBoxTop.addWidget(self.scroll)


if __name__ == "__main__":
    qt_app = QApplication(sys.argv)
    app = MainDupFiles()
    app.show()
    qt_app.exec_()

What should I do to make it works? BTW, I've tried the same with a QtDesiner code and I had the same problem.

alcarnielo
  • 55
  • 1
  • 9

1 Answers1

1

In your addLines method, you're creating yur scroll area with bottomWidget as its parent.

Then you add bottomWidget to outputWidget´s layout, which makesoutputWidget` its parent.

And then you set outputWidget as the content widget of scroll, so you're indirectly putting the scroll area into itsef:

scroll --> outputWidget --> bottonWidget --> scroll --> outputWidget...

If I replace

self.scroll = QScrollArea(self.bottonWidget)

with:

self.scroll = QScrollArea(self)

everything works fine.

mata
  • 67,110
  • 10
  • 163
  • 162