Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6931769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:37:12+00:00 2026-05-27T11:37:12+00:00

I’m trying to get a pyside button to copy text from a qlineEdit field

  • 0

I’m trying to get a pyside button to copy text from a qlineEdit field to a label and to a string variable. I have been through almost all of the Zetcode tutorials, but obviously I am missing something critical here. Be gentle, I’m a python newbie and a pyside newbie. I’m looking for more pyside tutorials.

I tried using my Qbutton to copy the text from the lineEdit, and then in a fit of desperation, I tried xxxxxxx

Here’s my code (any suggestions would be much appreciated, particularly with a link to where I can learn about what I needed to know):

Thank you for your help, Marc

import sys
from PySide import QtGui, QtCore   

class Example(QtGui.QWidget):
    def __init__(self):
        super(Example, self).__init__()        
        self.initUI()

    def initUI(self):
        nu_prg_name_label = QtGui.QLabel('Program Name:')
        author_label = QtGui.QLabel('Author')

        qle = QtGui.QLineEdit(self)
        qle.textChanged[str].connect(self.onChanged)

        # I added the buttons 
        okButton = QtGui.QPushButton("OK")
        cancelButton = QtGui.QPushButton("Cancel")

        grid = QtGui.QGridLayout()
        grid.setSpacing(4)

        # (arg__1, row, column, rowSpan, columnSpan[, alignment=0])
        grid.addWidget(nu_prg_name_label, 1, 0)
        grid.addWidget(author_label, 2, 0)
        grid.addWidget(qle, 1, 1, 1, 4)

        # I added the following 2 lines
        grid.addWidget(okButton, 3, 3)
        grid.addWidget(cancelButton, 3, 4)
        #grid.addWidget(review_label, 3, 0)

        # The QPushButton has a predefined 'signal' called 'clicked' 
        #   which is triggered every time that the button is pressed. 
        #   We will just 'connect' this signal to the sayHello() function:
        # Connect the button to the function
        okButton.clicked.connect(self.sendtxt2_qle)

        #grid.addWidget(author_label, 2, 0)
        #grid.addWidget(author_LineEdit02, 2, 1)

        #grid.addWidget(review_label, 3, 0)
        #grid.addWidget(review_TextEdit, 3, 1, 5, 1)

        self.setLayout(grid) 

        # Horizontal, vertical, width, length
        self.setGeometry(900, 300, 400, 100)
        self.setWindowTitle('Create Dirs [Info, TestArea, ItWorks] for a Program')    
        self.show()

    def onChanged(self, text):          
        nu_prg_name = self.qle.getText()
        self.author_label.setText(nu_prg_name) 
        print "Line 67: nu_prg_name = " + nu_prg_name   

    def sendtxt2_qle(self):
        nu_prg_name = self.grid.qle.getText()
        self.grid.author_label.setText(nu_prg_name) 
        print "Line 72: nu_prg_name = " + nu_prg_name

def main():
    app = QtGui.QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())   

if __name__ == '__main__':
    main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:37:13+00:00Added an answer on May 27, 2026 at 11:37 am

    There are several issues with the script you posted:

    1. author_label and qle are referenced outside the initUI method, so they need to be replaced with self.author_label and self.qle wherever they are used.
    2. The onChanged method tries to retrieve the line-edit text using the non-existent method getText. Use self.qle.text(), or, better still, use the text argument that is passed to the onChanged method by the textChanged signal.
    3. The sendtxt2_qle method has similar errors to (2), and also wrongly tries to reference qle and author_label as attributes of self.grid (which does not exist). See (1) for how to fix this.

    Note: When I ran the amended version of you script, I got some corrupted output from the print statements. This appears to be a bug in PySide, because the same script runs perfectly fine using PyQt4. (I’m using PySide-1.09.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.