尝试使用 QInputDialog 来获取一些输入,我希望它出现在鼠标光标处。我尝试过这个,但似乎不起作用;对话框每次都出现在相同的位置。
def createNewNote(self):
cursor_pos = QCursor.pos()
input_dialog = QInputDialog(self)
input_dialog.setWindowTitle("New Note")
input_dialog.setLabelText("Enter Note Name:")
input_dialog.setGeometry(cursor_pos.x(), cursor_pos.y(), input_dialog.width(), input_dialog.height())
ok = input_dialog.exec()
if ok:
title = input_dialog.textValue()
note_node = NoteNode(self)
note_node.move(cursor_pos)
note_node.setTitle(title)
self.note_nodes.append(note_node)
note_node.show()
请注意,这对于其他对象来说效果很好。
QInputDialog
.move()
和 .setGeometry()
方法似乎什么也没做。
尝试改变:
input_dialog.setGeometry(cursor_pos.x(), cursor_pos.y(), input_dialog.width(), input_dialog.height())
致:
input_dialog.setGeometry(cursor_pos.x(), cursor_pos.y(),cursor_pos.x() + input_dialog.width(), cursor_pos.y() + input_dialog.height())