Results 1 to 2 of 2

Thread: PyQt: How to manipulate QFileDialog

  1. #1
    Join Date
    Oct 2010
    Posts
    2
    Qt products
    Platforms
    Unix/X11

    Default PyQt: How to manipulate QFileDialog

    Hi,
    I have the same problem as
    http://www.qtcentre.org/threads/10504-QFileDialog
    Too bad the solution doesn't seem to work for me.

    I just want to add a widget to a QFileDialog. I tried many things like creating a QFileDialog instance and maniplulating it or its layout, to no effect. Now I even tried subclassing/inheriting and it doesn't give me an error, but changes nothing too:

    Qt Code:
    1. class myofd(QtGui.QFileDialog):
    2. def __init__(self,parent=None):
    3. super(myofd, self).__init__(parent)
    4. print "Columns: ",self.layout().columnCount()
    5. print "Rows: ",self.layout().rowCount()
    6. print "At 3-0: ",self.layout().itemAtPosition(3,0)
    7. self.layout().removeItem(self.layout().itemAtPosition(3,0))
    8. cmbo = QtGui.QComboBox()
    9. cmbo.addItem("MyChoice1")
    10. cmbo.addItem("MyChoice2")
    11. self.layout().addWidget(cmbo,4,0)
    12. self.layout().update()
    13. self.layout().activate()
    14. print "Columns: ",self.layout().columnCount()
    15. print "Rows: ",self.layout().rowCount()
    16. print "At 4-0: ",self.layout().itemAtPosition(4,0)
    17.  
    18. myloadinst = myofd()
    19. myloadinst.getOpenFileName(self,"Open log file ...","","")
    To copy to clipboard, switch view to plain text mode 

    The row count goes up, the ".itemAtPosition" function works, no errors are thrown... only the dialog doesn't contain the new widget.

    I've also tried the QLayout functions addChildWidget and addLayout and many more... also QFileDialog methods... sometimes I get a Runtime error:

    Qt Code:
    1. self.layout().addChildWidget(cmbo)
    2. RuntimeError: no access to protected functions or signals for objects not created from Python
    To copy to clipboard, switch view to plain text mode 

    which makes me think there may be some sip/c++/qt protection mechanisms which I don't know.

    Am I doing sth wrong? Is there a better way to do this? I hope I don't have to make a file dialog from scratch because QFileDialog is somehow immutable...

    Regards,
    Xaver

  2. #2
    Join Date
    Oct 2010
    Posts
    2
    Qt products
    Platforms
    Unix/X11

    Default Re: PyQt: How to manipulate QFileDialog

    Actually, might it be a problem that the QLayout object was created by C(++)? Wouldn't that mean any manipulation is impossible?
    Because if I translate this: http://developer.qt.nokia.com/faq/an...ialog_instance line-by-line, it's not working either:
    Qt Code:
    1. import sys
    2. from PyQt4 import QtCore,QtGui
    3.  
    4. app = QtGui.QApplication(sys.argv)
    5. box = QtGui.QFileDialog()
    6. button = QtGui.QPushButton(box)
    7. button.setText("New button")
    8. layout = box.layout()
    9. layout.addWidget(button, 0, 0)
    10. box.show()
    11. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 
    (Actually, is line 8 correct? I don't speak C++)

    Regards, Xaver

Similar Threads

  1. Replies: 5
    Last Post: 6th September 2009, 16:32
  2. How to manipulate a thread
    By avis_phoenix in forum Newbie
    Replies: 1
    Last Post: 18th August 2008, 23:34
  3. how to manipulate the keyboard event?
    By Ricardo_arg in forum Qt Programming
    Replies: 2
    Last Post: 4th August 2008, 07:49
  4. [java] manipulate a string
    By mickey in forum General Programming
    Replies: 5
    Last Post: 10th July 2008, 20:22
  5. Replies: 5
    Last Post: 21st November 2007, 20:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.