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 8323309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:41:11+00:00 2026-06-08T23:41:11+00:00

I am trying to get a minimal example for an application designed by the

  • 0

I am trying to get a minimal example for an application designed by the qt designer with pyqt involving a QTreeView to work

1) i can start the app this way but if i push the butten, no entry in the TreeView widget is shown, i do not get any error message, and the layout looks fine, is there some kind of update method?

if you answer, please be specific, as i am still a beginner with qt and much of the documentation is written with c++ examples, and i only have some experience with basic c and python

from PyQt4 import uic, QtGui, QtCore


(Ui_MainWindow, QMainWindow) = uic.loadUiType('main_window.ui')


class MainWindow(QtGui.QMainWindow):

    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.model = QtGui.QStandardItemModel()
        self.connect(self.ui.pushButton_NeuesMoebel, QtCore.SIGNAL('clicked()'), self.add_item)

    def add_item(self):
        t = self.ui.lineEdit_Moebel.text()
        if len(t) > 0: 
            item = QtGui.QStandardItem(t)
            self.model.appendRow(item)
            self.ui.lineEdit_Moebel.clear()
        else:
            self.ui.statusBar.showMessage('error: no text in Moebel')


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())

2) additionally, is there a cleaner way to directly use the *.ui file than this, to sort of directly subclass the MainWindow of the that file? the ui stuff seems a bit messy

3) for example it would be nicer to have the add_item method in a subclass of the window created by the *.ui file, are we supposed to use the intermediate step of translating the *.ui file to a *.py file?

  • 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-06-08T23:41:13+00:00Added an answer on June 8, 2026 at 11:41 pm

    You just forgot to set the model on your QTreeView. Right now the tree view has no model so it never sees the data update:

    def __init__(self, parent=None):
        ....
        self.ui.treeView.setModel(self.model)
    

    Also as a suggestion, save yourself some typing and use the new-style signal/slot connections that are more pythonic and don’t make you type out signatures:

    self.ui.pushButton_NeuesMoebel.clicked.connect(self.add_item)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get this expression to work, can someone look at it and tell
I'm trying to use the example found in: example , and I can get
Possible Duplicate: Trying to get tag-it to work with an AJAX call How can
I am trying get Struts 2 and Tiles to work and I am using
So I'm trying to work my way through this paper , which is primarily
I'm trying to write a (very minimal) WPF app which will look at a
I am currently trying to get OpenLayers to show a WMS-Layer. Doing this I
I'm trying to get a minimal form of dependent types in Scala. If I
I'm trying to get a fortran 90 application to open a fifo and write
So i am trying get 2 div-containers which both should contain centered text (Both

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.