Exemple #1
0
class App(QDialog):
    def __init__(self):
        app = QApplication(sys.argv)
        super().__init__()
        self.setWindowTitle('PyQt6 Grid Layout')
        self.setGeometry(100, 100, 320, 100)
        self.CreateGridLayout()

        self.windowLayout = QVBoxLayout()
        self.windowLayout.addWidget(self.horizontalGroupBox)
        self.setLayout(self.windowLayout)

        self.show()
        sys.exit(app.exec())

    def CreateGridLayout(self):
        self.horizontalGroupBox = QGroupBox("Grid")
        self.layout = QGridLayout()
        self.layout.setColumnStretch(2, 4)
        self.layout.setColumnStretch(1, 4)

        for label in "123456789":
            self.MakeButton(label)

        self.horizontalGroupBox.setLayout(self.layout)

    def MakeButton(self, label):
        button = QPushButton(label)
        button.clicked.connect(lambda: self.on_click(button))
        self.layout.addWidget(button)

    def on_click(self, pushButton):
        print('PyQt5 {0} button clicked.'.format(pushButton.text()))
Exemple #2
0
 def __init__(self):
     super(MainUi, self).__init__()
     self.setFixedSize(600,500)
     self.setWindowTitle("妹子图爬虫工具  version: 1.0.0 ")
     self.download_progressbar = QProgressBar()
     self.download_progressbar.setAlignment(QtCore.Qt.Alignment.AlignCenter)#文字居中
     self.download_progressbar.setStyleSheet(".QProgressBar::chunk { background-color: red;}")#背景
     self.download_progressbar.setValue(100)
     label01 = QLabel("下载URL:")
     label02 = QLabel("下载目录:")
     self.url_input    = QLineEdit()
     self.url_input.setText("https://www.mzitu.com/221746")
     self.url_input.setContentsMargins(0,0,0,0)
     self.download_dir = QLineEdit()
     self.download_dir.setContentsMargins(0,0,0,0)
     self.start_btn    = QPushButton("开始爬虫")
     self.start_btn.setFixedHeight(50)
     self.start_btn.setContentsMargins(0,0,0,0)
     inputlayout = QGridLayout()
     inputlayout.addWidget(label01, 0, 0) #第0行 0列
     inputlayout.addWidget(label02, 1, 0)
     inputlayout.addWidget(self.url_input, 0, 1)
     inputlayout.addWidget(self.download_dir, 1, 1)
     inputlayout.addWidget(self.start_btn, 0, 2, 2,1,QtCore.Qt.Alignment.AlignRight) #起始行,起始列, 占行数,占列数
     inputlayout.setColumnStretch(0, 1)  #设置每一列比例
     inputlayout.setColumnStretch(1, 10)
     inputlayout.setColumnStretch(2, 1)
     vlayout = QVBoxLayout()
     vlayout.addLayout(inputlayout)
     vlayout.addWidget(self.download_progressbar)
     self.frame = QFrame()
     self.frame.setFixedHeight(400)
     vlayout.addWidget(self.frame)
     vlayout.addStretch()
     inputlayout.setContentsMargins(0,0,0,0)
     vlayout01 = QVBoxLayout()
     self.frame.setLayout(vlayout01)
     self.qtablewidget = QTableWidget(1,3)
     self.qtablewidget.setHorizontalHeaderLabels(['目录','下载图片总数目', '删除'])
     vlayout01.addWidget(self.qtablewidget)
     self.qtablewidget.setColumnWidth(0, 358)  # 将第0列的单元格,设置成300宽度
     self.qtablewidget.setColumnWidth(1, 100 )  # 将第0列的单元格,设置成50宽度
     self.qtablewidget.verticalHeader().setVisible(False) #隐藏水平表头
     #self.qtablewidget.setDisabled(True) #设置不可编辑
     self.setLayout(vlayout)
     self.current_index = 0