# QLineEdit in extension UI: Cursor jumping to end of line (bug?)

**URL:** <https://discourse.slicer.org/t/qlineedit-in-extension-ui-cursor-jumping-to-end-of-line-bug/43954>\
**Category:** Development\
**Tags:** python, qt, extension-wizard\
**Created:** [August 4, 2025, 12:50pm UTC](https://discourse.slicer.org/t/qlineedit-in-extension-ui-cursor-jumping-to-end-of-line-bug/43954 "2025-08-04T12:50:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![shai-ikko](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shai-ikko/32/15765_2.png) [@shai-ikko](https://discourse.slicer.org/u/shai-ikko)\
**Post date:** [August 4, 2025, 12:50pm UTC](https://discourse.slicer.org/t/qlineedit-in-extension-ui-cursor-jumping-to-end-of-line-bug/43954/1 "2025-08-04T12:50:49Z")

</div>

Hi,

I’ve been writing some Slicer extensions using the Extension Wizard & Qt Designer, and it’s been mostly working very well. But I’m seeing a funny behavior, which I think is a bug.

I have extensions which use simple text fields – defined as a `QLineEdit` using the Qt Designer, and connected to the parameter node using the `SlicerParameterName` dynamic property (on the widget), which is handled by the `@parameterNodeWrapper` decorator on the Parameter Node class. I’ve compared my extension’s setup code with one created fresh by the Wizard, and AFAICT I’m not doing anything special, and not dropping any important initialization.

But the text lines behave as described [here](https://stackoverflow.com/questions/15801259/qlineedit-cursor-moves-to-end-after-textchanged-or-commitdata) – whenever a user types a character in the middle of the field, the cursor jumps to the end.

I suspect this is caused by not-careful-enough code in the GUI connection – it looks like the callback created for updating parameters from the GUI (in `parameterNodeWrapper.wrapper._makeGuiToParamCallback()` updates the parameter node, but then this updates the GUI back. I suppose this is useful in some cases. But if this is done for text fields, we probably need to restore the cursor position as described in the answers to the StackOverflow question cited above.

Have others also run into this?

[Edit: Related, of course, [Parameter node wrapper GUI connectors are missing for many widgets · Issue #7308 · Slicer/Slicer · GitHub](http://github.com/Slicer/Slicer/issues/7308) – but that lists `QLineEdit` as “supported”, which it mostly is]

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [August 4, 2025, 2:28pm UTC](https://discourse.slicer.org/t/qlineedit-in-extension-ui-cursor-jumping-to-end-of-line-bug/43954/2 "2025-08-04T14:28:40Z")

</div>

Yes, probably the text is being set again as part of the update. Saving and restoring the cursor position makes sense, or it could check if the value of the text is the same as what it’s trying to set and skip the update. It would make sense to add this to the wrapper code.

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [August 4, 2025, 10:31pm UTC](https://discourse.slicer.org/t/qlineedit-in-extension-ui-cursor-jumping-to-end-of-line-bug/43954/3 "2025-08-04T22:31:40Z")

</div>

What about this signal?

> **[QLineEdit Class | Qt Widgets | Qt 6.9.1](https://doc.qt.io/qt-6/qlineedit.html#editingFinished)**
>
> The QLineEdit widget is a one-line text editor.

HIH

---

<div class="post-metadata">

**Author:** ![shai-ikko](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shai-ikko/32/15765_2.png) [@shai-ikko](https://discourse.slicer.org/u/shai-ikko)\
**Post date:** [August 5, 2025, 1:52pm UTC](https://discourse.slicer.org/t/qlineedit-in-extension-ui-cursor-jumping-to-end-of-line-bug/43954/4 "2025-08-05T13:52:37Z")

</div>

I’ve been able to find some cases where it does work as intended, so there’s probably something a bit more involved going on. I will report more as I find out more.

---

<div class="post-metadata">

**Author:** ![shai-ikko](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shai-ikko/32/15765_2.png) [@shai-ikko](https://discourse.slicer.org/u/shai-ikko)\
**Post date:** [August 5, 2025, 3:40pm UTC](https://discourse.slicer.org/t/qlineedit-in-extension-ui-cursor-jumping-to-end-of-line-bug/43954/5 "2025-08-05T15:40:27Z")

</div>

No, scratch that. Those other cases were in an extension-in-development which had a broken field, and that field broke the connection to the parameter – so the cursor wasn’t jumping because the parameter wasn’t updated.

I see I am able to fix the bug by changing, in class `QLineEditToStrConnector`,

```auto
    def write(self, value: str) -> None:
        self._widget.text = value

```

to

```auto
    def write(self, value: str) -> None:
        # Writing the text of a QLineEdit moves the cursor to the end
        # We tolerate that if the value is actually changing
        if value != self._widget.text:
            self._widget.text = value

```

(this is one of the options suggested by @pieper IIUC)

I will post an issue and a PR for this. Thanks for your help!

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [August 5, 2025, 3:59pm UTC](https://discourse.slicer.org/t/qlineedit-in-extension-ui-cursor-jumping-to-end-of-line-bug/43954/6 "2025-08-05T15:59:16Z")

</div>

Yes, that looks good 👍

---

<div class="post-metadata">

**Author:** ![shai-ikko](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shai-ikko/32/15765_2.png) [@shai-ikko](https://discourse.slicer.org/u/shai-ikko)\
**Post date:** [August 5, 2025, 4:42pm UTC](https://discourse.slicer.org/t/qlineedit-in-extension-ui-cursor-jumping-to-end-of-line-bug/43954/7 "2025-08-05T16:42:50Z")

</div>

Just for closure, [GitHub · Where software is built](https://github.com/Slicer/Slicer/issues/8620) and [BUG: Avoid cursor jump on edit in extension LineEdit by shai-ikko · Pull Request #8621 · Slicer/Slicer · GitHub](https://github.com/Slicer/Slicer/pull/8621)

Thanks again!
