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.

4

1 回答 1

1

在您的addLines方法中,您正在创建您的滚动区域,bottomWidget并将其作为其父级。

然后将其父级添加bottomWidgetoutputWidget´s layout, which makesoutputWidget`。

然后您将其设置outputWidget为 的内容小部件scroll,因此您间接地将滚动区域放入 itsef 中:

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

如果我更换

self.scroll = QScrollArea(self.bottonWidget)

和:

self.scroll = QScrollArea(self)

一切正常。

于 2014-07-06T06:23:57.837 回答