Q: 如何使窗口置顶?
QtCore.Qt.WindowStaysOnTopHint
Example:
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtWidgets import QApplication , QMainWindow
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(368, 164)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
if __name__ == '__main__':
'''
主函数
'''
app = QApplication(sys.argv)
mainWindow = QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(mainWindow)
mainWindow.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
mainWindow.show()
sys.exit(app.exec_())
Q: QTextCursor 如何使用?
前提条件:获得指针对象
textCursor = self.textEdit.textCursor()
-
获取指定区间的文本(相对于整篇文档)
textCursor.setPosition(3, QTextCursor.MoveAnchor) textCursor.setPosition(9, QTextCursor.KeepAnchor) lineContent = textCursor.selectedText()
str = '0123456789'
3-9之间的字符为 345678
-
获取光标所在行的文本
textCursor.select(QTextCursor.LineUnderCursor) lineContent = textCursor.selectedText()
-
获取光标所在行的文本的前5个字符
textCursor.movePosition(QTextCursor.StartOfLine) end = textCursor.position() + 5 textCursor.setPosition(end, QTextCursor.KeepAnchor)
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。