reimplement QPlainText’s focusInEvent in another source file ,how to ?

62 views
Skip to first unread message

Philip

unread,
Nov 7, 2012, 4:51:40 AM11/7/12
to pyqt-...@googlegroups.com
The UI is as following
 
The UI is as following

I saved  the  form as a file named re.ui
Then I convert it into Python script named ui_re.py
Third ,I create the source file with the name
callFirstApp.pyw and import the ui_re.py to it

The code in the callFirstApp.pyw is as shown here:
@

import sys
from PySide.QtGui import *
from ui_re  import *

class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.plainTextEdit.setPlainText("Type code here...")
        
  

if __name__ == '__main__':
    app =QApplication(sys.argv)
    frame = MainWindow()
    frame.show()    
    app.exec_()
@
I want to reimplement the QPlainText’s focusInEvent in this file ,my code is as following 
(means let the default text "Type code here..." disappear when focus  in the QTextEdit’s editable area)

@
def focusInEvent(self, event):
        self.clear()
        QPlainTextEdit.focusInEvent(self, event)
@
But I don’t know how to add the code to the file correctly ?
Thanks in advance .

zw g

unread,
Nov 7, 2012, 7:02:07 AM11/7/12
to Philip, pyqt-pyside
I don't use designer at all.

In this situation, i will write a class to represent the UI(which inherits from QPlanTextEdit).
Then define a focusInEvent method for it.

That'd be much easier.

Gui



--
PyQt & PySide的交流信息:
 
QQ群号: 143061743
邮件列表: pyqt-...@googlegroups.com
---
您收到此邮件是因为您订阅了 Google 网上论坛的“PyQt & PySide”论坛。
要向此网上论坛发帖,请发送电子邮件至 pyqt-...@googlegroups.com
要取消订阅此网上论坛,请发送电子邮件至 pyqt-pyside...@googlegroups.com
通过以下网址访问此论坛:http://groups.google.com/group/pyqt-pyside?hl=zh-CN。
 
 

Jimmy Kuu

unread,
Nov 7, 2012, 8:15:49 AM11/7/12
to pyqt-...@googlegroups.com
When you designe the ui, you don't need to place the QPlainTextEdit in the main window.

You should inherited A QPlainTextEdit and reimplemented the focusInEvent method.

Then in the MainWindow's __init__, you can insert the PlainTextEdit into the ui window.

好吧,英文很烂,不知能不能看懂。

zw g

unread,
Nov 7, 2012, 8:58:12 AM11/7/12
to Jimmy Kuu, pyqt-pyside
I believe what Jimmy told was also to suggest you write the QPlainTextEdit stuff inside your "callFirstApp.pyw" file.

丸子写的我懂了。我英语也很烂。
Allow me, no offense, 一个小地方: 
You should inherited --> You should inherit    # (should 后接原形)
还有后面的reimplemented也改成一般时态就可以了。

Hope it helps :)

Gui


--

Jimmy Kuu

unread,
Nov 7, 2012, 9:05:12 AM11/7/12
to pyqt-...@googlegroups.com, Jimmy Kuu
haha, 废了me老大劲write的。

在 2012年11月7日星期三UTC+8下午9时58分34秒,zw g写道:
I believe what Jimmy told was also to suggest you write the QPlainTextEdit stuff inside your "callFirstApp.pyw" file.

丸子写的我懂了。我英语也很烂。
Allow me, no offense, 一个小地方: 
You should inherited --> You should inherit    # (should 后接原形)
还有后面的reimplemented也改成一般时态就可以了。

Hope it helps :)

Gui


On Wed, Nov 7, 2012 at 9:15 PM, Jimmy Kuu <jimm...@gmail.com> wrote:
When you designe the ui, you don't need to place the QPlainTextEdit in the main window.

You should inherited A QPlainTextEdit and reimplemented the focusInEvent method.

Then in the MainWindow's __init__, you can insert the PlainTextEdit into the ui window.

好吧,英文很烂,不知能不能看懂。
Reply all
Reply to author
Forward
0 new messages