当前位置: 首页>>代码示例>>Python>>正文


Python QTextEdit.setPlaceholderText方法代码示例

本文整理汇总了Python中PyQt5.Qt.QTextEdit.setPlaceholderText方法的典型用法代码示例。如果您正苦于以下问题:Python QTextEdit.setPlaceholderText方法的具体用法?Python QTextEdit.setPlaceholderText怎么用?Python QTextEdit.setPlaceholderText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.Qt.QTextEdit的用法示例。


在下文中一共展示了QTextEdit.setPlaceholderText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: EditQDialog

# 需要导入模块: from PyQt5.Qt import QTextEdit [as 别名]
# 或者: from PyQt5.Qt.QTextEdit import setPlaceholderText [as 别名]
class EditQDialog(QDialog):
    """
        Class who create Edit QDialog to edit text in Alignak-app
    """

    def __init__(self, parent=None):
        super(EditQDialog, self).__init__(parent)
        self.setWindowTitle('Edit Dialog')
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setStyleSheet(settings.css_style)
        self.setWindowIcon(QIcon(settings.get_image('icon')))
        self.setObjectName('dialog')
        self.setFixedSize(300, 300)
        # Fields
        self.text_edit = QTextEdit()
        self.old_text = ''

    def initialize(self, title, text):
        """
        Initialize QDialog for UserNotesQDialog

        :param title: title of the QDialog
        :type title: str
        :param text: text to edit
        :type text: str
        """

        self.old_text = text
        center_widget(self)

        # Main status_layout
        main_layout = QVBoxLayout(self)
        main_layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(main_layout)

        main_layout.addWidget(get_logo_widget(self, title))

        text_title = QLabel(_("Edit your text:"))
        text_title.setObjectName('subtitle')
        main_layout.addWidget(text_title)
        main_layout.setAlignment(text_title, Qt.AlignCenter)

        main_layout.addWidget(self.get_text_widget())

    def get_text_widget(self):
        """
        Return text QWidget with QTextEdit

        :return: text QWidget
        :rtype: QWidget
        """

        text_widget = QWidget()
        text_widget.setObjectName('dialog')
        text_layout = QVBoxLayout()
        text_widget.setLayout(text_layout)

        self.text_edit.setPlaceholderText(_('type your text...'))
        self.text_edit.setText(self.old_text)
        text_layout.addWidget(self.text_edit)

        # Accept button
        accept_btn = QPushButton(_('Confirm'), self)
        accept_btn.clicked.connect(self.accept_text)
        accept_btn.setObjectName('valid')
        accept_btn.setMinimumHeight(30)
        text_layout.addWidget(accept_btn)

        return text_widget

    def accept_text(self):
        """
        Set Edit QDialog to Rejected or Accepted (prevent to patch for nothing)

        """

        if self.old_text == self.text_edit.toPlainText():
            self.reject()
        elif not self.old_text or self.old_text.isspace():
            if not self.text_edit.toPlainText() or self.text_edit.toPlainText().isspace():
                self.reject()
            else:
                self.accept()
        else:
            self.accept()
开发者ID:Alignak-monitoring-contrib,项目名称:alignak-app,代码行数:87,代码来源:dialogs.py


注:本文中的PyQt5.Qt.QTextEdit.setPlaceholderText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。