Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I prevent a QTextArea from being erased?
    primarykey
    data
    text
    <p>I have a QPlainTextEdit in a modal dialog window (subclass of QDialog). Whenever I minimize the dialog and bring it back up, all the text in the QTextArea has disappeared.</p> <p>How can I preserve the text in my QPlainTextEdit widget?</p> <p>I've tried saving the text in the textedit widget like this:</p> <pre><code>def __init__(self): self.text_area = self.QPlainTextEdit() self.previous_text = '' def hideEvent(self, event): self.previous_text = self.text_area.toPlainText() def showEvent(self, event): self.text_area.setPlainText(self.previous_text) </code></pre> <p>But this approach didn't yield any appreciable results.</p> <p><strong>EDIT:</strong> I've noticed that this only happens when I can actually hide the modal dialog ... which seems to only be possible when I use Xmonad as my window manager ... whenever I try this in GNOME or on Windows, this behavior cannot be reproduced because those window managers actually prevent the modal dialog from being minimized.</p> <p><strong>EDIT:</strong> Following @Avaris's comment below, I tried enabling minimization for the modal <code>QDialog</code> like so:</p> <pre><code>def __init__(self): ... self.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint) </code></pre> <p>With this flag set, the vanishing text behavior can be replicated on Windows, GNOME and XMonad.</p> <p>Here is a visual example from my Windows machine before I minimize the window: <img src="https://i.stack.imgur.com/mtJ9P.png" alt="Before I minimize the window"></p> <p>And here's what it looks like after I bring up the window again: <img src="https://i.stack.imgur.com/g3bWu.png" alt="After I minimize the window"></p> <p><strong>EDIT:</strong> Text is written to the modal dialog's <code>QPlainTextEdit</code> like so:</p> <pre><code>def write(self, text): self.text_area.insertPlainText(QtCore.QString(text)) </code></pre> <p>The text itself is retrieved as a python string from a system of threads whose standard out has been captured and redirected. By the time is gets to the above <code>write()</code> function, the text itself is simply a python string.</p> <p><strong>EDIT:</strong> When I modify the <code>write</code> method mentioned above like so (following @ekhumoro's suggestion):</p> <pre><code>def write(self, text): self.text_area.insertPlainText(text) </code></pre> <p>The text is still missing after hiding and showing the dialog.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload