可以使用QLineEdit的setReadOnly方法将"."后面的部分设置为只读。

from PyQt5.QtWidgets import QApplication, QLineEdit, QInputDialog

app = QApplication([])

input_dialog = QInputDialog()

line_edit = QLineEdit(input_dialog)
line_edit.setText("1.jpg")

# 获取"."的位置
dot_index = line_edit.text().index('.')
# 设置"."后面的部分为只读
line_edit.setReadOnly(True)
line_edit.setCursorPosition(dot_index + 1)

input_dialog.show()

app.exec_()

在这个例子中,我们首先创建一个QLineEdit对象,并将其设置为QInputDialog的子对象。然后,我们将文本设置为"1.jpg"。然后,我们使用index()方法获取"."的位置,并使用setReadOnly()方法将"."后面的部分设置为只读。最后,我们使用setCursorPosition()方法将光标定位到"."后面的位置。

这样,用户就无法修改"."后面的部分了。

QInputDialog设置text为1jpg如何设置后面的部分不可修改

原文地址: https://www.cveoy.top/t/topic/jbRE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录