1
其實我有兩個問題:如何把一個表到QMessageBox提示
- 我能在其他地方的QMessageBox提示(在QDialog的用於爲例等等)一個「顯示詳細信息」按鈕?
- 如何將一個tableWidget放到QMessageBox中?
其實我有兩個問題:如何把一個表到QMessageBox提示
這是將tableWidget放入QMessageBox的示例代碼。 如果你不期待這個答案,對不起。
import sys
from PyQt4 import QtCore, QtGui
class MyMessageBox(QtGui.QMessageBox):
def __init__(self):
QtGui.QMessageBox.__init__(self)
self.setSizeGripEnabled (True)
self.setWindowTitle ('Hello MessageBox ???')
#Create QPushButton in QMessageBox
self.addButton (QtGui.QPushButton('Accept'), QtGui.QMessageBox.YesRole)
self.addButton(QtGui.QPushButton('Reject'), QtGui.QMessageBox.NoRole)
self.addButton(QtGui.QPushButton('Cancel'), QtGui.QMessageBox.RejectRole)
#Add TableWidget to QMessageBox
self.addTableWidget (self)
#Return values while clicking QPushButton
currentClick = self.exec_()
if currentClick==0 :
print 'Accept'
if currentClick==1 :
print 'Reject'
if currentClick==2 :
print 'Cancel'
#Create TableWidget
def addTableWidget (self, parentItem) :
self.tableWidget = QtGui.QTableWidget(parentItem)
self.tableWidget.setGeometry (QtCore.QRect(0, 0, 540, 250))
self.tableWidget.setObjectName ('tableWidget')
self.tableWidget.setColumnCount(5)
self.tableWidget.setRowCount(6)
#Allow resizing of QMessageBox
def event(self, e):
result = QtGui.QMessageBox.event(self, e)
self.setMinimumWidth(0)
self.setMaximumWidth(16777215)
self.setMinimumHeight(0)
self.setMaximumHeight(16777215)
self.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
self.resize(550, 300)
return result
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
ex = MyMessageBox()
#ex.show()
sys.exit(app.exec_())
#Thanks,
#Subin Gopi
乍一看,它看起來太複雜了,只是應該顯示一條短消息的qmessagebox。創建一個QDialog來做你想做的事情不應該很難 – SnoozeTime