def __init__(self): # -------------------- # avoid error message: # [xcb] Most likely this is a multi-threaded client and XInitThreads has not been called # QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_X11InitThreads) # -------------------- self.app = QtGui.QApplication(sys.argv) MainWindow = QtGui.QMainWindow() self.ui = untitled.Ui_MainWindow() self.ui.setupUi(MainWindow) MainWindow.show() self.model = QtGui.QStandardItemModel() self.model.setColumnCount(2) headerNames = [] headerNames.append("active") headerNames.append("comment") self.model.setHorizontalHeaderLabels(headerNames) if False: for i in range(100): row1 = [QtGui.QStandardItem('active' if i%2 else ''), QtGui.QStandardItem( 'data_'+str(i)) ]; self.model.appendRow( row1) self.ui.tableView.setModel(self.model) self.ui.statusbar.showMessage("hugo") self.selectionModel = QtGui.QItemSelectionModel(self.model) self.ui.tableView.setSelectionModel( self.selectionModel ) # selectionModel.selectionChanged(on_selection_changed) print("---") print (QtCore.SIGNAL("clicked()")) self.controller = ExampleAppController(self) self.controller.setModel(self.model) self.controller.setSelectionModel(self.selectionModel) QtCore.QObject.connect(self.selectionModel, QtCore.SIGNAL("selectionChanged(QItemSelection, QItemSelection)"), self.controller.on_selection_changed) QtCore.QObject.connect( self.ui.actionExit, QtCore.SIGNAL("triggered()"), self.controller.on_exit_clicked) QtCore.QObject.connect( self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.controller.on_button_clicked) #ui.statusbar.showMessage("System Status | Normal") sys.exit(self.app.exec_())
def main(): # Client init app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = untitled.Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.setFixedSize(1280,720) ui.stackedWidget.setCurrentIndex(0) ui.tabWidget.setCurrentIndex(0) ui.LoginButton.clicked.connect(lambda: initClient(ui.IPInput.text())) MainWindow.show() eventhandler = event_handler() sys.exit(app.exec_())
import sys import untitled from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow if __name__ == '__main__': app = QApplication(sys.argv) mainWindow = QMainWindow() ui = untitled.Ui_MainWindow() ui.setupUi(mainWindow) mainWindow.show() print(ui.pushButton.sizeHint().width()) print(ui.pushButton.sizeHint().height()) ui.pushButton sys.exit(app.exec_())
mainwindow_ui.tableWidget.setItem(row_number - 1, 0, QTableWidgetItem(str(i))) mainwindow_ui.tableWidget.setItem(row_number - 1, number, QTableWidgetItem(str(result[i][0]))) # mainwindow_ui.tableWidget.setItem(2, 2, QTableWidgetItem("123")) mainwindow_ui.tableWidget.setItem(row_number - 1, number + 1, QTableWidgetItem(str(result[i][1]))) if __name__ == '__main__': getProblems = pyqtSignal(str, int, int) insertRow = pyqtSignal() app = QApplication(sys.argv) mainwindow_ui = mw.Ui_MainWindow() qMainWindow = QMainWindow() mainwindow_ui.setupUi(qMainWindow) qMainWindow.show() # 设置按钮图标 icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap("../img/file.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) mainwindow_ui.toolButton.setIcon(icon) # 设置按钮的事件监听 mainwindow_ui.toolButton.clicked.connect(lambda: pick_in()) mainwindow_ui.pushButton.clicked.connect(lambda: check_start())