How to read from QTextedit in python?

If all you need is the displayed text in your QTextEdit widget, you can access that by using the toPlainText() method on the widget you need the text from. Example: mytext = self.textEdit.toPlainText() At this point, you can do whatever you want with mytext. You can write it to a file, you can manipulated it, … Read more

PyQt: RuntimeError: wrapped C/C++ object has been deleted

This answer to this question is as found here: Python PySide (Internal c++ Object Already Deleted) Apparently, assigning one widget to QMainWindow using setCentralWidget and then assigning another widget with setCentralWidget will cause the underlying c++ QWidget to be deleted, even though I have an object that maintains reference to it. Note: QMainWindow takes ownership … Read more

Embedding IPython Qt console in a PyQt application

Ok, this code seems to do the trick (i.e. it puts a non-blocking ipython interpreter in a Qt widget, which can be embedded into other widgets). Keywords passed to terminal_widget get added to the namespace of the widget import atexit from IPython.zmq.ipkernel import IPKernelApp from IPython.lib.kernel import find_connection_file from IPython.frontend.qt.kernelmanager import QtKernelManager from IPython.frontend.qt.console.rich_ipython_widget import … Read more

PEP8 and PyQt, how to reconcile function capitalization?

In your shoes, I wouldn’t fight your framework, just like, as a general principle, I don’t fight City Hall;-). I happen to share your preference for lowercase-with-underscore function names as PEP 8 specifies, but when I’m programming in a framework that forces a different capitalization style, I resign myself to adopting that style too, since … Read more

How can I move file into Recycle Bin / trash on different platforms using PyQt4?

It’s a good thing you’re using Python, I created a library to do just that a while ago: http://www.hardcoded.net/articles/send-files-to-trash-on-all-platforms.htm On PyPI: Send2Trash Installation Using conda: conda install Send2Trash Using pip: pip install Send2Trash Usage Delete file or folders from send2trash import send2trash send2trash(“directory”)

PySide / PyQt detect if user trying to close window

Override the closeEvent method of QWidget in your main window. For example: class MainWindow(QWidget): # or QMainWindow … def closeEvent(self, event): # do stuff if can_exit: event.accept() # let the window close else: event.ignore() Another possibility is to use the QApplication‘s aboutToQuit signal like this: app = QApplication(sys.argv) app.aboutToQuit.connect(myExitHandler) # myExitHandler is a callable

What are good practices for avoiding crashes / hangs in PyQt?

General Programming Practices If you must use multi-threaded code, never-ever access the GUI from a non-GUI thread. Always instead send a message to the GUI thread by emitting a signal or some other thread-safe mechanism. Be careful with Model/View anything. TableView, TreeView, etc. They are difficult to program correctly, and any mistakes lead to untraceable … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)