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

  • SEARCH
  • Home
  • 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 7042455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:10:13+00:00 2026-05-28T02:10:13+00:00

Its simple as it can be, but I cant do it. I have txt

  • 0

Its simple as it can be, but I cant do it.

I have txt file which contains name,surname, mail and telephone number like that:

name surname phone mail 
name surname phone mail
name surname phone mail

Everything is seperated with tabs and after the mail there is newline at the end of each line

Now I want to search the file for the specific name im searching and to show the results when I click the button Search in TableWidget (using python Qt).

Its simple, but I have some errors I cant resolve.

Thanks for the help.

  • 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-28T02:10:14+00:00Added an answer on May 28, 2026 at 2:10 am

    You have two possible steps to accomplish here.

    1. Read the data into your model
    2. Interact with your tablewidget and your search field

    To get your started, a simple and straightforward approach for reading in your data would be to use the csv module. You could also create a custom table model that would read directly from a csv file, but I think thats beyond our level right now.

    Here is a simple way to get your text file into a data structure:

    import csv
    
    people = []
    reader = csv.reader(open('people.txt'), delimiter='\t')
    for row in reader:
        people.append(row)
    

    Now people will contain all your lines in the form: (name, surname, email)

    From here, you can populate your TableWidget. This is a really basic snippet that should give you the idea:

    from PyQt4 import QtGui
    
    rowCount = len(people)
    colCount = max([len(p) for p in people])
    
    tableWidget = QtGui.QTableWidget()
    tableWidget.setRowCount(rowCount)
    tableWidget.setColumnCount(colCount)
    
    for row, person in enumerate(people):
        for column, value in enumerate(person):
            newItem = QtGui.QTableWidgetItem(value)
            tableWidget.setItem(row, column, newItem)
    

    The colCount is just a little protection in case you have unbalanced amounts of fields on each line. Again this is just a general approach.

    From here its a little open ended as to how you want to do the search. But what you could do is connect you search button to a method that handles the search. Keep in mind I am writing all this as just global functions. You would probably have your class, and be using self everywhere. But I am keeping it short and simple:

    myButton.clicked.connect(search)
    
    def search(*args, **kwargs):
        value = myLineEdit.text()
        items = tableWidget.findItems(value, QtCore.Qt.MatchContains)
        if items:
            # scroll to the first match?
            tableWidget.scrollToItem(items[0], tableWidget.PositionAtCenter)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fairly simple script but something is going wrong and I can't
It's simple to observe the documents scroll event but I can't seem to find
Sure it's a simple question, but I can't fix it, can somebody help me?
I know it's a simple question, but I can't seem to drag it out
I have a simple website I'm testing. It's running on localhost and I can
Well, I have a simple question, at least I hope its simple. I was
This really has my stumped today. I'm sure its simple, but... Here is my
I'm sure this is a simple issue, but I have noticed that when I
This should be simple but i cant seem to get it going. The purpose
it's should be something really simple if its possible. anyway of doing so? can't

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.