PyQt:更改 QInputDialog 的位置(PyQt6)

问题描述 投票:0回答:1

尝试使用 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()
方法似乎什么也没做。

python python-3.x pyqt pyqt6
1个回答
0
投票

尝试改变:

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())
© www.soinside.com 2019 - 2024. All rights reserved.