<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[PySide2] How do I send backspace as a QKeyEvent?]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I have created a virtual keyboard in my application using PySide2.</p>
<p dir="auto">And I am using the QKeyEvent to pass the key that is being pressed using the following code:</p>
<pre><code>        button = self.sender()
        widget = QApplication.focusWidget()
        
        if (button.text() == "\u232b"):
            widget.backspace()
        elif (button.text() == "Space"):
            text = " "
        elif (button.text() == "&amp;&amp;"):
            text = "&amp;"
        else:
            text = button.text()
        
        
        if(button.text() != "\u232b"):
            key = button.property("_key_")
            
            if hasattr(key, "toPyObject"):
                key = key.toPyObject()
            
            if widget:
                event = QtGui.QKeyEvent(
                    QtCore.QEvent.KeyPress, key, QtCore.Qt.NoModifier, text
                )
                QtCore.QCoreApplication.postEvent(widget, event)
</code></pre>
<p dir="auto">My question is that how can I pass the backspace key?<br />
I have a backspace button which runs the function of .backspace() which works on LineEdits but is limited to that. Other widgets do not have this option, such as the dateEdit widget.</p>
<p dir="auto">Any suggestions?</p>
]]></description><link>https://forum.qt.io/topic/113891/pyside2-how-do-i-send-backspace-as-a-qkeyevent</link><generator>RSS for Node</generator><lastBuildDate>Fri, 07 Aug 2026 15:24:20 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/113891.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 21 Apr 2020 10:46:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [PySide2] How do I send backspace as a QKeyEvent? on Wed, 22 Apr 2020 00:37:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/lolcocks">@<bdi>lolcocks</bdi></a> mmm, Your code is unclear so it would be great if you provide a Minimum Reproducible Example (MRE), on the other hand you must send  <code>key = QtCore.Qt.Key_Backspace</code></p>
]]></description><link>https://forum.qt.io/post/590076</link><guid isPermaLink="true">https://forum.qt.io/post/590076</guid><dc:creator><![CDATA[eyllanesc]]></dc:creator><pubDate>Wed, 22 Apr 2020 00:37:03 GMT</pubDate></item><item><title><![CDATA[Reply to [PySide2] How do I send backspace as a QKeyEvent? on Thu, 23 Apr 2020 15:36:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/eyllanesc">@<bdi>eyllanesc</bdi></a> said in <a href="/post/590076">[PySide2] How do I send backspace as a QKeyEvent?</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/lolcocks">@<bdi>lolcocks</bdi></a> mmm, Your code is unclear so it would be great if you provide a Minimum Reproducible Example (MRE), on the other hand you must send  <code>key = QtCore.Qt.Key_Backspace</code></p>
</blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/denni-0">@<bdi>Denni-0</bdi></a> said in <a href="/post/590206">[PySide2] How do I send backspace as a QKeyEvent?</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/lolcocks">@<bdi>lolcocks</bdi></a> sending <code>QtCore.Qt.Key_Backspace</code> simply equates to what you are doing using the actual key-codes <strong>so it is not a must use</strong> -- now grant you these key-codes have already been enumerated for you via this method but it all kind of depends on why you are doing what you are doing as to what the best solution would be for your program so use the option you feel is best.</p>
</blockquote>
<p dir="auto">Thank you both of you.<br />
I am going to go with eyllanesc's solution as it works the best for me. You know, because it sends an actual backspace key.</p>
]]></description><link>https://forum.qt.io/post/590396</link><guid isPermaLink="true">https://forum.qt.io/post/590396</guid><dc:creator><![CDATA[lolcocks]]></dc:creator><pubDate>Thu, 23 Apr 2020 15:36:37 GMT</pubDate></item><item><title><![CDATA[Reply to [PySide2] How do I send backspace as a QKeyEvent? on Wed, 22 Apr 2020 00:37:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/lolcocks">@<bdi>lolcocks</bdi></a> mmm, Your code is unclear so it would be great if you provide a Minimum Reproducible Example (MRE), on the other hand you must send  <code>key = QtCore.Qt.Key_Backspace</code></p>
]]></description><link>https://forum.qt.io/post/590076</link><guid isPermaLink="true">https://forum.qt.io/post/590076</guid><dc:creator><![CDATA[eyllanesc]]></dc:creator><pubDate>Wed, 22 Apr 2020 00:37:03 GMT</pubDate></item></channel></rss>