欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

pyqt5 textEdit、lineEdit操作的示例代碼

 更新時間:2020年08月12日 09:53:40   作者:cpf945  
這篇文章主要介紹了pyqt5 textEdit、lineEdit操作的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

1.定義一個textEdit/lineEdit:(lineEdit只需要將代碼中的QTextEdit改為QLineEdit)

  self.textEdit = QtWidgets.QTextEdit(Dialog)
  self.textEdit.setGeometry(QtCore.QRect(70, 90, 171, 391))
  self.textEdit.setObjectName("textEdit")
  self.textEdit.setReadOnly(True)#設(shè)置為只讀,即可以在代碼中向textEdit里面輸入,但不能從界面上輸入,沒有這行代碼即可以從界面輸入

2.從代碼中將字符串顯示到textEdit:

str='要顯示的字符串'
self.textEdit.setText(str)

3.追加字符串:

 str='要顯示的字符串'
 self.textEdit_2.append(str)

4.顯示數(shù)字到textEdit:數(shù)字必須要轉(zhuǎn)換成字符串

count=10
str=str(count)
self.textEdit.setText(str)

5.讀取textEdit中的文字:textEdit和LineEdit中的文字讀取方法是不一樣的

str1 = self.textEdit.toPlainText()
#textEdit 用toPlainText()方法
#linEdit 直接用self.lineEdit.text()即可獲取

PyQt5 QTextEdit控件操作

from PyQt5.Qt import *
import sys
import math

#超鏈接
class MyTextEdit(QTextEdit):
  def mousePressEvent(self,me):
    print(me.pos())
    link_str=self.anchorAt(me.pos())
    if(len(link_str)>0):
      QDesktopServices.openUrl(QUrl(link_str))
    return super().mousePressEvent(me)

class Window(QWidget):
  def __init__(self):
    super().__init__()
    self.setWindowTitle("QTextEdit的學習")
    self.resize(500,500)
    self.setWindowIcon(QIcon("D:\ICO\ooopic_1540562292.ico"))
    self.setup_ui()
  def setup_ui(self):
    te=MyTextEdit(self)
    self.te=te
    te.move(100,100)
    te.resize(300,300)
    te.setStyleSheet("background-color:cyan;")

    but=QPushButton(self)
    but.move(50,50)
    but.setText("測試按鈕")
    #self.占位文本的提示()
    self.文本內(nèi)容的設(shè)置()
    #self.格式設(shè)置和合并()
    but.pressed.connect(self.but_test)
    #te.textCursor().insertTable(5,3)
    #te.insertHtml("xxx"*300+"<a name='lk' href='#itlike'>撩課</a>"+"aaa"*200)
    te.insertHtml("xxx"*300+"<a *200)

    te.textChanged.connect(self.text_change)#文本發(fā)生改變
    te.selectionChanged.connect(self.selection_change)#選中的文本發(fā)生改變
    te.copyAvailable.connect(self.copy_a)#復制是否可用
  def copy_a(self,yes):
    print("復制是否可用",yes)

  def selection_change(self):
    print("文本選中的內(nèi)容發(fā)生了改變")

  def text_change(self):
    print("文本內(nèi)容發(fā)生了改變")

  def but_test(self):
    #self.te.clear()
    #self.光標插入內(nèi)容()
    #self.內(nèi)容和格式的獲取()
    #self.字體設(shè)置()
    #self.顏色設(shè)置()
    #self.字符設(shè)置()
    #self.常用編輯操作()
    #self. 只讀設(shè)置()
    #self.AB功能測試()
    self.打開超鏈接()

  def 打開超鏈接(self):
    pass
  def AB功能測試(self):
    #self.te.setTabChangesFocus(True)
    print(self.te.tabStopDistance())
    self.te.setTabStopDistance(100)

  def 只讀設(shè)置(self):
    self.te.setReadOnly(True)
    self.te.insertPlainText("itlike")

  def 滾動到錨點(self):
    self.te.scrollToAnchor("lk")

  def 常用編輯操作(self):
    #self.te.copy()
    #self.te.paste()
    #self.te.selectAll()
    #self.te.setFocus()
    #QTextDocument.FindBackward
    print(self.te.find("xx",QTextDocument.FindBackward|QTextDocument.FindCaseSensitively))
    self.te.setFocus()

  def 字符設(shè)置(self):
    tcf=QTextCharFormat()
    tcf.setFontFamily("宋體")
    tcf.setFontPointSize(20)
    tcf.setFontCapitalization(QFont.Capitalize)
    tcf.setForeground(QColor(100,200,150))
    self.te.setCurrentCharFormat(tcf)
    tcf2=QTextCharFormat()
    tcf2.setFontOverline(True)
    #self.te.setCurrentCharFormat(tcf2)
    self.te.mergeCurrentCharFormat(tcf2)

  def 顏色設(shè)置(self):
    self.te.setTextBackgroundColor(QColor(200,10,10))
    self.te.setTextColor(QColor(10,200,10))

  def 字體設(shè)置(self):
    #QFontDialog.getFont()
    self.te.setFontFamily("幼圓")
    self.te.setFontWeight(QFont.Black)
    self.te.setFontItalic(True)
    self.te.setFontPointSize(30)
    self.te.setFontUnderline(True)
    #font=QFont()
    #font.setStrikeOut(True)
    #self.te.setCurrentFont(font)


  def 對齊方式(self):
    self.te.setAlignment(Qt.AlignCenter)

  def 光標設(shè)置(self):
    print(self.te.cursorWidth())
    if self.te.overwriteMode():
      self.te.setOverwriteMode(False)
      self.te.setCursorWidth(1)
    else:
      self.te.setOverwriteMode(True)
      self.te.setCursorWidth(10)
  def 覆蓋模式的設(shè)置(self):
    self.te.setOverwriteMode(True)
    print(self.te.overwriteMode())

  def 軟換行模式(self):
    #self.te.setLineWrapMode(QTextEdit.NowWrap)
    #self.te.setLineWrapMode(QTextEdit.FixedPixelWidth)
    self.te.setLineWrapMode(QTextEdit.FixedColumnWidth)
    self.te.setLineWrapColumnOrWidth(8)
  def 自動格式化(self):
    QTextEdit
    self.te.setAutoFormatting(QTextEdit.AutoBulletList)#錄入*號自動產(chǎn)生格式
  def 開始和結(jié)束編輯塊(self):
    tc=self.te.textCursor()
    #tc.beginEditBlock()
    tc.insertText("123")
    tc.insertBlock()
    tc.insertText("456")
    tc.insertBlock()
    #tc.cndEditBlock()

    tc.insertText("789")
    tc.insertBlock()
  def 位置相關(guān)(self):
    tc=self.te.textCursor()#獲取光標
    print("是否在段落的結(jié)尾",tc.atBlockEnd)
    print("是否在段落的開始",tc.atBlockStart())
    print("是否在文檔的結(jié)尾",tc.atEnd())
    print("是否在文檔的開始",tc.atStart())
    print("在第幾列",tc.columnNumber())
    print("光標位置",tc.position())
    print("在文本塊中的位置",tc.positionInBlock())
  def 文本字符的刪除(self):
    tc=self.te.textCursor()
    #tc.deleteChar()#向右側(cè)清除
    tc.deletePreviousChar()#向左側(cè)清除
    self.te.setFocus()
  def 文本的其他操作(self):
    tc=self.te.textCursor()
    #print(tc.selectionStart())#獲取選中起始
    #print(tc.selectionEnd())#獲取選中結(jié)束
    #tc.clearSelection()#清除選中
    #self.te.setTextCursor()#設(shè)置光標
    #print(tc.hasSelection())
    tc.removeSelectedText()
    self.te.setFocus()
  def 文本選中內(nèi)容的獲取(self):
    tc=self.te.textCursor()
    print(tc.selectedText())
    QTextDocumentFragment
    print(tc.selection().toPlainText())
    print(tc.selectedTableCells())
  def 文本選中和清空(self):
    tc=self.te.textCursor()
    #tc.setPosition(6,QTextCursor,KeepAnchor)
    #tc.movePosition(QTextCursor.Up,QTextCursor.KeepAnchor,1)
    tc.select(QTextCursor.WordUnderCursor)
    self.te.setTextCursor(tc)

  def 格式設(shè)置和合并(self):
    #設(shè)置上下間距
    tc=self.te.textCursor()
    tcf=QTextCharFormat()
    tcf.setFontFamily("幼圓")
    tcf.setFontPointSize(30)
    tcf.setFontOverline(True)
    tcf.setFontUnderline(True)
    tc.setCharFormat(tcf)
    return None

    #設(shè)置上下劃線及字體大小
    tc=self.te.textCursor()
    tcf=QTextCharFormat()
    tcf.setFontFamily("幼圓")
    tcf.setFontPointSize(30)
    tcf.setFontOverline(True)
    tcf.setFontUnderline(True)
    tc.setBlockCharFormat(tcf)
    pass

  def 內(nèi)容和格式的獲取(self):
    tc=self.te.textCursor()
    QTextLine
    print(tc.block().text())
    print(tc.blockNumber())
    #print(tc.currentList().count())
    pass
  def 文本內(nèi)容的設(shè)置(self):
    #設(shè)置普通文本內(nèi)容
    self.te.setPlainText("<h1>ooo</h1>")
    self.te.insertPlainText("<h1>ooo</h1>")
    print(self.te.toPlainText())
    #富文本的操作
    self.te.setHtml("<h1>ooo</h1>")
    self.te.insertHtml("<h6>社會我的順哥</h6>")
    print(self.te.toHtml())

  def 占位文本的提示(self):
    self.te.setPlaceholderText("請輸入你的個人簡介")

  def 光標插入內(nèi)容(self):
    tc=self.te.textCursor()#獲取焦點
    tff=QTextFrameFormat()
    tff.setBorder(10)
    tff.setBorderBrush(QColor(100,50,50))
    tff.setRightMargin(50)
    tc.insertFrame(tff)
    doc=self.te.document()
    root_frame=doc.rootFrame()
    root_frame.setFrameFormat()
    return None
    tc=self.te.textCursor()#獲取光標
    tbf=QTextBlockFormat()
    tcf=QTextCharFormat()
    tcf.setFontFamily("隸書")
    tcf.setFontItalic(True)
    tcf.setFontPointSize(20)
    tbf.setAlignment(Qt.AlignRight)#對齊
    tbf.setRightMargin(100)
    tc.insertBlock(tbf,tcf)
    self.te.setFocus()#焦點
    return None
    #創(chuàng)建或插入添加表格
    tc=self.te.textCursor()
    ttf=QTextTableFormat()
    ttf.setAlignment(Qt.AlignRight)
    ttf.setCellPadding(6)
    ttf.setCellSpacing(13)


    ttf.setColumnWidthConstraints((QTextLength(QTextLength.PercentageLength,50),QTextLength(QTextLength.PercentageLength,40),QTextLength(QTextLength.PercentageLength,10)))#單元格長度比例

    table=tc.insertTable(5,3,ttf)
    table.appendColumns(2)
    return None

    #設(shè)置對齊
    tc=self.te.textCursor()
    #tl=tc.insertList(QTextListFormat.ListCircle)
    #tl=tc.insertList(QTectListFormat.ListDecimal)
    #tl=tc.createList(QTextListFormat.ListDecimal)
    tlf=QTextListFormat()
    tlf.setIndent(3)
    tlf.setNumberPrefix("<<")
    tlf.setNumberSuffix("<<")
    tlf.setStyle(QTextListFormat.ListDecimal)
    tl=tc.createList(tlf)
    QTextList
    return None

    #插入普通文本或者富文本
    tc=self.te.textCursor()
    tdf=QTextDocumentFragment.fromHtml("<h1>xxx</h1>")
    #tdf=QTextDocumentFragment.fromPlainText("<h1>xxx</h1>")
    tc.insertFragment(tdf)
    return None
    #插入圖片
    tc=self.te.textCursor()
    tif=QTextImageFormat()
    tif.setName("D:\ICO\ooopic_1517621187.ico")
    tif.setWidth(100)
    tif.setHeight(100)
    tc.insertImage("D:\ICO\mmmmm.JPG")

    return None
    #插入接
    QTextCursor
    tcf=QTextCharFormat()
    tcf.setToolTip("撩課學院網(wǎng)址")
    tcf.setFontFamily("隸書")
    tcf.setFontPointSize(12)
    tc=self.te.textCursor()
    tc.insertText("itlike.com",tcf)
    tc.insertHtml("<a )

if __name__=="__main__":
  App=QApplication(sys.argv)
  Win=Window()
  Win.show()
  sys.exit(App.exec_())

到此這篇關(guān)于pyqt5 textEdit、lineEdit操作的示例代碼的文章就介紹到這了,更多相關(guān)pyqt5 textEdit、lineEdit操作內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python中使用MySQL模糊查詢的詳細方法

    Python中使用MySQL模糊查詢的詳細方法

    這篇文章主要介紹了Python中使用MySQL模糊查詢的方法,以下是一個使用pymysql進行模糊查詢的詳細示例,包括安裝庫、連接數(shù)據(jù)庫、執(zhí)行查詢以及處理結(jié)果,需要的朋友可以參考下
    2024-06-06
  • python 使用三引號時容易犯的小錯誤

    python 使用三引號時容易犯的小錯誤

    這篇文章主要介紹了python 使用三引號時容易犯的小錯誤,幫助新手學習,避免入坑,感興趣的朋友可以了解下
    2020-10-10
  • 3分鐘看懂Python后端必須知道的Django的信號機制

    3分鐘看懂Python后端必須知道的Django的信號機制

    這篇文章主要介紹了3分鐘看懂Python后端必須知道的Django的信號機制,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-07-07
  • Python同時處理多個異常的方法

    Python同時處理多個異常的方法

    這篇文章主要介紹了Python同時處理多個異常的方法,文中講解非常細致,代碼幫助大家更好的理解和學習,感興趣的朋友可以了解下
    2020-07-07
  • Python繪制股票移動均線的實例

    Python繪制股票移動均線的實例

    今天小編就為大家分享一篇Python繪制股票移動均線的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-08-08
  • Pygame?Font模塊使用教程

    Pygame?Font模塊使用教程

    文本是任何一款游戲中不可或缺的重要要素之一,本文將主要介紹Pygame中Font模塊的使用教程,例如文本的繪制、顯示等,感興趣的同學可以了解一下
    2021-11-11
  • Python如何將一個EXCEL表拆分多個excel表

    Python如何將一個EXCEL表拆分多個excel表

    在Python中,你可以使用pandas庫來讀取Excel文件,并將一個大的Excel表格(工作表)拆分成多個單獨的Excel文件,這篇文章主要介紹了Python如何將一個EXCEL表拆分多個excel表,需要的朋友可以參考下
    2024-06-06
  • Python在游戲中的熱更新實現(xiàn)

    Python在游戲中的熱更新實現(xiàn)

    本文主要介紹了Python在游戲中的熱更新實現(xiàn),文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • 對PyQt5基本窗口控件 QMainWindow的使用詳解

    對PyQt5基本窗口控件 QMainWindow的使用詳解

    今天小編就為大家分享一篇對PyQt5基本窗口控件 QMainWindow的使用詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-06-06
  • 13行python代碼實現(xiàn)對微信進行推送消息的示例代碼

    13行python代碼實現(xiàn)對微信進行推送消息的示例代碼

    本文主要介紹了13行python代碼實現(xiàn)對微信進行推送消息的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-08-08

最新評論