pyqt文字框按回車觸發事件
主要內容
- 通過繼承實現自己的介面類;
- 涉及模組:QDialog, QLineEdit , QTextBrowser
- 介面佈局:絕對佈局,佈局類
例項講解
先看一段程式碼,我們定義了一個類Form,它繼承自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 |
class Form(QDialog):
def __init__( self ,
parent = None ):
super (Form, self ).__init__(parent)
self .browser = QTextBrowser()
self .lineedit = QLineEdit( "Type
an expression and press Enter" )
self .lineedit.selectAll()
layout = QVBoxLayout() #垂直盒式佈局
layout.addWidget( self .browser) layout.addWidget( self .lineedit)<br>
#layout
= QGridLayout() #網格佈局
#layout.addWidget(self.browser,0,
0)
#layout.addWidget(self.lineedit,0,
0)
self .setLayout(layout)
self .lineedit.setFocus()
self .connect( self .lineedit,
SIGNAL( "returnPressed()" ), self .updateUi) #訊號繫結到槽 self .setWindowTitle( "Calculate" )
def
|