Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

jagne kvrj, ngochan1126@hotmail.­com, a asdfghjhhjjkl', cvezrtg, chink chinese frankies, lambhead@rocketmail.com, priwalfdept77@yahoo.de, from scipy.optimize import minpack2 ImportError: DLL load failed: 找不到指定的模块。, yamlå, adfghjshjklç

Links

XODOX
Impressum

#1: pyqt中cellChanged信号需要在tablewidget中编辑两次才能触发

Posted on 2012-09-11 07:06:46 by 双人鱼

æè¿åä¸ä¸ªå°æ¡é¢è½¯ä»¶ççé¢ï¼ç±äºæ°´å¹³æéï¼è®©èªå·²åå°½äºè¦å¤´ã好å¨æèé±¼ç主ç­è¿äºå¤§çç帮å©ä¸ï¼è®©èªå·²éæ­¥è¿æ­¥ã
æè¿åçé¢ï¼ä¸­å¿é¨ä»¶ç¨çæ¯QTableWidgetï¼ç±äºéè¦ç¨å°å¤æ­è¡¨æ ¼æ°æ®æ¯å¦è¢«ä¿®æ¹çåè½ï¼æ以æ±å©äºåä½å¤§çãå¨å¤§çç帮å©ä¸ä½¿ç¨äºcellChangedï¼ä½¿å¾çé¢è½æ­£å¸¸è¿è¡ãä½åç°åªæ对两个ååæ ¼è¿è¡ç¼è¾åæè½è§¦åä¿¡å·cellChangedï¼ä¸ç¥æ¯ä¸ºä»ä¹ï¼ååºæ样解å³ï¼
æåçæµè¯æ¯è¿æ ·çãè¿è¡ä»£ç åï¼å¯¹è¡¨æ ¼ä¸­çä¸ä¸ªååæ ¼è¿è¡äºç¼è¾ï¼ç¶åç¹å»æå¼æé®ï¼æèªå·²ç设计åºå¼¹åºæ示ä¿å­ç对è¯æ¡ï¼ä½å®éä¸æ²¡æå¼¹åºãä¹å°±æ¯è¯´cellChangedä¿¡å·å¹¶æ²¡æ触åãä½æ¯å¦æå对å¦ä¸ä¸ªååæ ¼è¿è¡è¾ï¼åææå¼æé®æ¶ï¼åå¯ä»¥æ­£å¸¸å°å¼¹åºæ示ä¿å­ç对è¯æ¡ã
æç°å¨åªåæå¼æé®çæµè¯ï¼æ以å¶å®é¨åç代ç è¿æ²¡æä¿®æ¹ã代ç å¦ä¸ï¼

#!/usr/bin/env python
#coding=utf-8
import sip
sip.setapi('QVariant', 2)

from PyQt4 import QtCore, QtGui

import application_rc


class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()


self.table = QtGui.QTableWidget(5,5)
self.setCentralWidget(self.table)
self.new_dirty()
self.table.cellChanged.connect(self.makeDirty)

self.createActions()
self.createMenus()
self.createToolBars()
self.createStatusBar()


def new_dirty(self):
self.dirty = False #å建æ°è¡¨æ ¼æ¶ï¼ææ¡£éæ°è®¾ç½®ä¸ºæªä¿®æ¹

def makeDirty(self):
self.dirty = True



def newFile(self):
if self.maybeSave():
self.textEdit.clear()
self.setCurrentFile('')
#å½æ°ä½ç¨ï¼æ°å»ºæ件ç¹å»åå®ç°çæ¹æ³ï¼æ§½ï¼ãå½ç¹å»æ°å»ºï¼å¦æå½å以ææå¼çææ¬ï¼
#åå¤æ­ææ¬æ¯å¦è¢«ä¿®æ¹ä¿å­ï¼å¦æ没被修æ¹ï¼ç´æ¥æææ¬ç¼è¾çå容æ¸æï¼å¹¶ææ°å»ºçææ¬å设为Untitle.txtã
#å¦æå·²ç»è¢«ä¿®æ¹ï¼å°±æ§è¡maybeSave()éç return slotSave();è¿è¡ä¿å­

def open(self):
if self.maybeSave():#maybeSave()ç¨æ¥å¤æ­å½å已修æ¹çæ件æ¯å¦è¿è¡äºä¿å­
fileName = QtGui.QFileDialog.getOpenFileName(self)
if fileName:
self.loadFile(fileName)
#å½æ°ä½ç¨ï¼ç¹å»æå¼é项å®ç°çæ¹æ³ï¼æ§½ï¼
#ç¹å»æå¼ææ¬ï¼åå¤æ­å½åå·²ç»æå¼çææ¬æ¯å¦ä¿å­
#å¦æä¿å­äºï¼å°±è·³åºæ件对è¯æ¡ï¼è¾å¥è¦æå¼çæ件åï¼å¹¶æ该æ件åèµå¼ç»fileName,fileNameä¸ä¸ºç©ºï¼æå¼è¯¥æ件


def save(self):
if self.curFile:
return self.saveFile(self.curFile)

return self.saveAs()
#å½æ°ä½ç¨ï¼ç¹å»ä¿å­æå®ç°çæ¹æ³ï¼æ§½ï¼
#å¦æå½åææ¬å为空ï¼å°±æ§è¡å¦å­ä¸ºæ¹æ³
#å¦æä¸ä¸ºç©ºï¼å°±æ§è¡ä¿å­ææ¬çæ¹æ³

def saveAs(self):
fileName = QtGui.QFileDialog.getSaveFileName(self)
if fileName:
return self.saveFile(fileName)
return False
#å½æ°ä½ç¨ï¼ç¹å»å¦å­ä¸ºé项å®ç°çæ¹æ³
#ç¹å»å¦å­ä¸ºè·³åºæ件对è¯æ¡ï¼è¾å¥å¦å­ä¸ºåå­å¹¶ææ¹åå­èµå¼ç»fileName
#å¦æ没è¾å¥å¦å­ä¸ºåå­èæ¯éæ©äºåæ¶ï¼è¿åfalse
#å¦æè¾å¥ï¼ç¨è¿ä¸ªåå­ä¿å­ææ¬



def createActions(self):
self.newAct = QtGui.QAction(QtGui.QIcon(':/images/new.png'), u"æ°å»º(&N)",
self, shortcut=QtGui.QKeySequence.New,
statusTip=u"æ°å»ºä¸ä¸ªææ¡£", triggered=self.newFile)

self.openAct = QtGui.QAction(QtGui.QIcon(':/images/open.png'),
u"æå¼(&O)...", self, shortcut=QtGui.QKeySequence.Open,
statusTip=u"æå¼ä¸ä¸ªç°å­çææ¡£", triggered=self.open)

self.saveAct = QtGui.QAction(QtGui.QIcon(':/images/save.png'),
u"ä¿å­(&S)", self, shortcut=QtGui.QKeySequence.Save,
statusTip=u"ä¿å­æ´»å¨ææ¡£", triggered=self.save)

self.saveAsAct = QtGui.QAction(u"å¦å­ä¸º(&A)...", self,
shortcut=QtGui.QKeySequence.SaveAs,
statusTip=u"ç¨æ°å称ä¿å­è¯¥æ´»å¨ææ¡£",
triggered=self.saveAs)

self.exitAct = QtGui.QAction(u"éåº(&X)", self, shortcut="Ctrl+Q",
statusTip=u"éåºç¨åºï¼æ示ä¿å­ææ¡£", triggered=self.close)


def createMenus(self):
self.fileMenu = self.menuBar().addMenu(u"æ件(&F)")
self.fileMenu.addAction(self.newAct)
self.fileMenu.addAction(self.openAct)
self.fileMenu.addAction(self.saveAct)
self.fileMenu.addAction(self.saveAsAct)
self.fileMenu.addSeparator();
self.fileMenu.addAction(self.exitAct)



def createToolBars(self):
self.fileToolBar = self.addToolBar("File")
self.fileToolBar.addAction(self.newAct)
self.fileToolBar.addAction(self.openAct)
self.fileToolBar.addAction(self.saveAct)



def createStatusBar(self):
self.statusBar().showMessage("Ready")



def maybeSave(self):#å½æ°ä½ç¨ï¼å¤æ­æ件æ¯å¦ä¿å­äº
if self.dirty:#è°ç¨ AddãClearãInsert æ Remove æ¹æ³åï¼IsModified å±æ§ä¸º trueã æ­¤å¤ï¼ä½¿ç¨ Item å±æ§ä¿®æ¹å­ç¬¦ä¸²éåçåç´ åï¼IsModified å±æ§ä¹ä¸º trueã
#æ¯å¤æ­ææ¬ç¼è¾çå容æ¯å¦è¢«ä¿®æ¹ï¼å¦æ被修æ¹å°±è·³åºä¸ä¸ªè­¦å对è¯æ¡ï¼é®æ¯å¦ä¿å­ã忽ç¥ãåæ¶ã
ret = QtGui.QMessageBox.warning(self, u"supermemoä¼´ä¾£ (é±¼ç)",
u"ææ¬å容已ç»è¢«ä¿®æ¹\nä½ æ³ä¿å­è¢«ä¿®æ¹çå容åï¼",
QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard |
QtGui.QMessageBox.Cancel)
if ret == QtGui.QMessageBox.Save:
return self.save()#å¦æéæ©ä¿å­ï¼æ§è¡ä¿å­æ¹æ³ï¼
elif ret == QtGui.QMessageBox.Cancel:
return False#å¦æéæ©åæ¶ï¼è¿åfalse
return True#å¦æ没被修æ¹ï¼è¿åtrue
#å¤æ­æ件æ¯å¦ä¿å­å½æ°maybeSave()çè¿åå¼å¦ä¸ï¼
#1ãå¦æææ¬ä¿å­è¿äºï¼ä¹å°±æ¯æ²¡è¢«ä¿®æ¹ï¼åè¿åTrue
#2ãå¦æææ¬è¢«ä¿®æ¹è¿äºï¼å¹¶ä¸å¨å¼¹åºçè­¦å对è¯æ¡ä¸­éæ©äºåæ¶ï¼åè¿åFalse
#3ãå¦æææ¬è¢«ä¿®æ¹è¿äºï¼å¹¶ä¸å¨å¼¹åºçè­¦å对è¯æ¡ä¸­éæ©äºä¿å­ï¼åä¸è¿åä»»ä½å¼ï¼ç´æ¥æ§è¡ä¿å­å½æ°self.save()



def saveFile(self, fileName):
file = QtCore.QFile(fileName)
if not file.open(QtCore.QFile.WriteOnly | QtCore.QFile.Text):
QtGui.QMessageBox.warning(self, "Application",
"Cannot write file %s:\n%s." % (fileName, file.errorString()))
return False

outf = QtCore.QTextStream(file)
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
outf << self.textEdit.toPlainText()
QtGui.QApplication.restoreOverrideCursor()

self.setCurrentFile(fileName);
self.statusBar().showMessage("File saved", 2000)
return True
#å½æ°ä½ç¨ï¼æææ¬ç¼è¾çå容ä¿å­å°ææ¬éé¢
#åæ°å»ºææ¬ï¼æå¼ææ¬ï¼å¦ææå¼å¤±è´¥ä¼è·³åºä¸ä¸ªé误对è¯æ¡ï¼æ¾ç¤ºä¸è½å
#å¦ææå¼æåï¼æ°å»ºä¸ä¸ªææ¬æµout,æææ¬ç¼è¾çå容é½è¾åºå°ææ¬æµï¼å¹¶è®¾ç½®å½åçææ¬å为ä¿å­æ¶åçææ¬åã



if __name__ == '__main__':

import sys

app = QtGui.QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
sys.exit(app.exec_())

--

â» æ¥æº:ã»æ°´æ¨ç¤¾åº http://newsmth.netã»

Report this message