Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] How to add a list to ScrollArea and select one file from that?
Forum Updated to NodeBB v4.3 + New Features

[Solved] How to add a list to ScrollArea and select one file from that?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    ukpyqt
    wrote on 14 May 2014, 11:09 last edited by
    #1

    Hi guys,

    I am new to Python and QT designer, I got stuck in ScrollArea where I want to insert file names (fnames) to scrollArea and select one file from that. Please help me fix it, Thanks in advance

    Code:

    @@class Main(QtGui.QMainWindow):

    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.pushButton1.clicked.connect(self.buttonClicked)
        self.ui.pushButton_2.clicked.connect(self.buttonToClose)
        
    def buttonToClose(self):
        QtGui.qApp.quit()
    
    def buttonClicked(self):
        fdir = QtGui.QFileDialog.getExistingDirectory()
        if fdir == '':
            self.ui.lineEdit1.setText('Please select the folder...')
        else:
            self.ui.lineEdit1.setText(fdir)
            fnames = os.listdir(path=fdir)
            
        self.listWidget = QtGui.QListWidget(self)
        self.someLayout.addWidget(self.listWidget)
        self.listWidget.addItems(fnames)
    

    if name == 'main':
    app = QtGui.QApplication(sys.argv)
    window = Main()
    window.show()
    sys.exit(app.exec_()) @@

    Error:

    Traceback (most recent call last):
    File "C:\Users\ramas\workspace\PlotGraph_1\Main.py", line 48, in buttonClicked
    self.someLayout.addWidget(self.listWidget)
    AttributeError: 'Main' object has no attribute 'someLayout'

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Soraltan
      wrote on 14 May 2014, 11:32 last edited by
      #2

      Welcome here,

      apparently someone has to define the member-variable called 'someLayout'. At least in the code given it is never actually defined. So in the constructor you would expect something like

      @
      self.someLayout = QtGui.HBoxLayout()
      self.centralWidget().setLayout(self.someLayout)
      @

      Or something of that type.

      However, as you seem to be using a .ui File created witht he QtDesigner and then translated via pyuic I would suppose there is already some Layout set. So you probably want to use
      @
      self.centralWidget().layout().addWidget(self.listWidget)
      @

      instead. Hope it helps.

      Soraltan

      1 Reply Last reply
      0
      • U Offline
        U Offline
        ukpyqt
        wrote on 14 May 2014, 13:02 last edited by
        #3

        Thanks for your help, since I had problem in ScrollArea have changed to listWidget and it worked...

        @ def buttonClicked(self):
        fdir = QtGui.QFileDialog.getExistingDirectory()
        if not fdir:
        self.ui.lineEdit1.setText('Please select the folder...')
        return

            self.ui.lineEdit1.setText(fdir)
            fnames = os.listdir(path=fdir)
            
            self.ui.listWidget.clear()
            self.ui.listWidget.addItems(fnames)@
        

        thanks for your help, much appreciated....

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Soraltan
          wrote on 14 May 2014, 13:06 last edited by
          #4

          So, the code that caused the trouble is no longer there, right?!? Ok, so this thread is solved then (even by omitting the original problem)?!?

          I'm a bit confused here :-)

          1 Reply Last reply
          0
          • U Offline
            U Offline
            ukpyqt
            wrote on 14 May 2014, 13:58 last edited by
            #5

            Sorry Soraltan, I have removed the old code and replaced with listWidget. This problem is solved for now, like you have mentioned by omitting the original problem. Thanks for your time and help.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Soraltan
              wrote on 14 May 2014, 14:00 last edited by
              #6

              Ok, glad it works for you now. Please mark this thread as solved by prepending [solved] within the title.

              Best

              Soraltan

              1 Reply Last reply
              0

              1/6

              14 May 2014, 11:09

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved