How to show a QDialog
在包含
在按下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | class Widget(QWidget): def __init__(self,md,parent=None): QWidget.__init__(self,parent) layout=QVBoxLayout(self) # initially construct the visible table tv = QTableView() # uncomment this if the last column shall cover the rest tv.horizontalHeader().setStretchLastSection(True) tv.show() # set black grid lines self.setStyleSheet("gridline-color: rgb(39, 42, 49)") # construct the Qt model belonging to the visible table model = NvmQtModel(md) tv.setModel(model) tv.resizeRowsToContents() tv.resizeColumnsToContents() # set the shortcut ctrl+F for find in menu shortcut = QShortcut(QKeySequence('Ctrl+f'), self) shortcut.activated.connect(self.handleFind) # delegate for decimal delegate = NvmDelegate() tv.setItemDelegate(delegate) self.setGeometry(200,200,600,600) # adjust this later layout.addWidget(tv) # set window title self.setWindowTitle("TITLE") # find function: search in the first column of the table def handleFind(self): reply = QMessageBox.question( self, 'Find', 'Find Dialog', QMessageBox.Yes | QMessageBox.No) if reply == QMessageBox.Yes: print('Yes') else: print('No') |
然后我将
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | class Widget(QWidget): def __init__(self,md,parent=None): QWidget.__init__(self,parent) layout=QVBoxLayout(self) # initially construct the visible table tv = QTableView() # uncomment this if the last column shall cover the rest tv.horizontalHeader().setStretchLastSection(True) tv.show() # set black grid lines self.setStyleSheet("gridline-color: rgb(39, 42, 49)") # construct the Qt model belonging to the visible table model = NvmQtModel(md) tv.setModel(model) tv.resizeRowsToContents() tv.resizeColumnsToContents() # set the shortcut ctrl+F for find in menu shortcut = QShortcut(QKeySequence('Ctrl+f'), self) shortcut.activated.connect(self.handleFind) # delegate for decimal delegate = NvmDelegate() tv.setItemDelegate(delegate) self.setGeometry(200,200,600,600) # adjust this later layout.addWidget(tv) # set window title self.setWindowTitle("TITLE") # find function: search in the first column of the table def handleFind(self): findDialog = QDialog() findLabel = QLabel("Find what", findDialog) findField = QLineEdit(findDialog) findButton = QPushButton("Find", findDialog) closeButton = QPushButton("Close", findDialog) findDialog.show() |
如果希望对话框为模式对话框,请调用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | from PyQt4.QtGui import * def handleFind(): findDialog = QDialog() #findDialog.setModal(True) findLabel = QLabel("Find what", findDialog) findField = QLineEdit(findDialog) findButton = QPushButton("Find", findDialog) closeButton = QPushButton("Close", findDialog) #findDialog.show() findDialog.exec_() app = QApplication([]) b = QPushButton("click me") b.clicked.connect(handleFind) b.show() app.exec_() |