def pop_up(self, text='', move=True): """ Shows the dialog, setting the current text to `text`, and blocks the caller until the user has made a choice. If the user entered a label, that label is returned, otherwise (i.e. if the user cancelled the action) `None` is returned. """ self.edit.setText(text) self.edit.setSelection(0, len(text)) self.edit.setFocus(Qt.PopupFocusReason) if move: cursor_pos = QCursor.pos() # move OK button below cursor btn = self.button_box.buttons()[0] self.adjustSize() btn.adjustSize() offset = btn.mapToGlobal(btn.pos()) - self.pos() offset += QPoint(btn.size().width() // 4, btn.size().height() // 2) cursor_pos.setX(max(0, cursor_pos.x() - offset.x())) cursor_pos.setY(max(0, cursor_pos.y() - offset.y())) parent_bottom_right = self.parentWidget().geometry() max_x = parent_bottom_right.x() + parent_bottom_right.width( ) - self.sizeHint().width() max_y = parent_bottom_right.y() + parent_bottom_right.height( ) - self.sizeHint().height() max_global = self.parentWidget().mapToGlobal(QPoint(max_x, max_y)) if cursor_pos.x() > max_global.x(): cursor_pos.setX(max_global.x()) if cursor_pos.y() > max_global.y(): cursor_pos.setY(max_global.y()) self.move(cursor_pos) return trimmed(self.edit.text()) if self.exec_() else None
def list_item_click(self, t_qlist_widget_item): text = trimmed(t_qlist_widget_item.text()) self.edit.setText(text)
def post_process(self): self.edit.setText(trimmed(self.edit.text()))
def validate(self): if trimmed(self.edit.text()): self.accept()