码迷,mamicode.com
首页 > 其他好文 > 详细

pyqt练习x3.20

时间:2014-12-14 22:38:19      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   os   sp   for   on   

#_*_ coding: utf-8 _*_

from PyQt4.QtCore import *

from PyQt4.QtGui import *

import sys

QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8"))

class FindDialog(QDialog):

    def __init__(self,parent = None):

        super(FindDialog, self).__init__(parent)

        self.setWindowTitle(self.tr("Find"))

        # QLabel控件中显示的图像和文字的位置可以用setAlignmentsetIndent方法调整。文字内容也可以用setWordWrap方法分成几行。

        label = QLabel(self.tr("Find &what:"))

        lineEdit = QLineEdit()

        # setBuddy方法可以将QLabel控件与QLineEdit控件联系起来,从而将键盘焦点转移到QLineEdit控件上

        label.setBuddy(lineEdit)

        caseCheckBox = QCheckBox(self.tr("Match &case"))

        backwardCheckBox = QCheckBox(self.tr("Search &backward"))

        self.findButton = QPushButton(self.tr("&Find"))

        self.findButton.setDefault(True)

        self.findButton.setEnabled(False)

        closeButton = QPushButton(self.tr("Close"))

        QObject.connect(lineEdit,SIGNAL("textChanged(const QString &)"),self.enableFindButton)

        QObject.connect(self.findButton, SIGNAL("clicked()"), self.findClicked)

        QObject.connect(closeButton, SIGNAL("clicked()"), self, SLOT("close()"))

        topLeftLayout = QHBoxLayout()

        topLeftLayout.addWidget(label)

        topLeftLayout.addWidget(lineEdit)

        leftLayout = QVBoxLayout()

        leftLayout.addLayout(topLeftLayout)

        leftLayout.addWidget(caseCheckBox)

        leftLayout.addWidget(backwardCheckBox)

        rightLayout = QVBoxLayout()

        rightLayout.addWidget(self.findButton)

        rightLayout.addWidget(closeButton)

        rightLayout.addStretch()

        mainLayout = QHBoxLayout()

        mainLayout.addLayout(leftLayout)

        mainLayout.addLayout(rightLayout)

        self.setLayout(mainLayout)

        self.setFixedHeight(self.sizeHint().height())

        # 自定义TAB键的顺序,只两个参数不方便

        # QWidget.setTabOrder(closeButton,self.findButton)

        #QWidget.setTabOrder(self.findButton,backwardCheckBox)

    def findNext(str,cs):

        pass

    def findPrevious(str,cs):

        pass

    def findClicked(self):

        text = lineEdit.text()

        if caseCheckBox.isChecked():

            cs = Qt.CaseSensitive

        else:

            cs = Qt.CaseInsensitive

        if backwardCheckBox.isChecked():

            self.findPrevious.emit(text,cs)

        else: self.findNext.emit(text,cs)

    def enableFindButton(self, text):

        self.findButton.setEnabled(not text.isEmpty())

app = QApplication(sys.argv)

aaa = FindDialog()

aaa.show()

app.exec_()  # 测试ALT+W, ALT+C, ALT+B, ALT+F,默认的TAB键是控制创建的顺序 # QWidget::setTabOrder()可以改变这个顺序  # connect(lineEdit, SIGNAL(textChanged(const QString &)),this, SIGNAL(updateRecord(const QString &)))

 bubuko.com,布布扣

pyqt练习x3.20

标签:style   blog   http   io   ar   os   sp   for   on   

原文地址:http://www.cnblogs.com/mhxy13867806343/p/4163134.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!