I want to make a QT4 (using QT designer) dialog, that contains a part where a file has to be selected.
Now, I know QFileDialog exists, and I can program something that does what I want.
But can I also just do it in QT designer?
Is there some way to get a "file select" widget in QT designer?
Or, I remember these buttons, having the selected file as a title and a little arrow allowing the user to select another file by the QFileDialog?
So is there a ready made solution, or do I have to program it myself?
There is no file dialog available from the Qt designer as far as I know. But you can easily do it with a few lines of code.
Assuming you have a simple button called pushButton and the path should be stored in lineEdit.
def selectFile():
lineEdit.setText(QFileDialog.getOpenFileName())
pushButton.clicked.connect(selectFile)
[edit]Just wondering though, are you using KDE by any chance? If so, than you can use the KUrlRequester for this. It can easily be configured to support anything from files to urls to directories.
QFileDialog exists in QtGui. At least in my version 4.4 and probably much earlier too. I think the reason it is not in Designer is because it opens its own window instead of being a widget to place on another window.
The documentation from QTDesigner could be better and at least hint of its existence.
Instantiate it and run the show command. It comes right up and defaults to /.
import QtGui
self.fileDialog = QtGui.QFileDialog(self)
self.fileDialog.show()
You can use method getOpenFileName() in QFileDialog Class.
QFileDialog.getOpenFileName() will return the file path and the selected file type
I got this : ('C:/Users/Sathsara/Desktop/UI/Test/test.py', 'All Files (*)')
To get only the file path use QFileDialog.getOpenFileName()[0]
Sample code:
def selectFile():
print(QFileDialog.getOpenFileName()[0])
dlg.locationBtn.clicked.connect(selectFile)
Related
I want to create my own very simple editor of .txt files. As in real editors, I want that if you change the file and don't save it yet, the name of file will start with '*' (for example, *some_text_file.txt).
I think that fot this I should check QPlainTextEdit after the file was downloaded to editor and after the user pushed button 'save'. But I don't know how to check QPlainTextEdit without user control, but after some changes. Or maybe there is another way to do it. So, how to do it?
You could use the textChanged signal from the QPlainTextEdit. It indicates when the input text has changed. See:
https://doc.qt.io/qt-5/qplaintextedit.html#textChanged
Roughly, you would do the following:
load the file
display the filename without asterisk
connect the textChanged signal into a slot (function) that will add asterisk to the filename
when the Save button is pressed, remove the asterisk
If you're a Qt beginner, you might want to read about the Qt signal and slot mechanism:
https://doc.qt.io/qt-5/signalsandslots.html
I am working on QT Designer to build GUI App. I want to ask how add command for push button.
For example I want to apply this action :
self.NfmtLoginButton.clicked.connect(lambda: SecondScript.printme(self.NfmtPasswordEntry.text()))
Is it possible through the QT Designer. to be permanently saved. and no need to add all the commands again when generating new python script file from UI file.
No, it's not possible, but that should not be a problem, as the files generated using pyuic should never, ever be modified (the warning in those files is not to be undertaken).
Those files should always be left unmodified and only updated again with pyuic, as they are only meant to be imported in the actual program file, as explained in the official guidelines about using Designer (the "multiple inheritance approach is generally the most suggested).
The PyQt5 docs says
"New signals defined in this way will be automatically added to the
class’s QMetaObject. This means that they will appear in Qt Designer"
How do I make anything appear in QtDesigner if it only knows how to open *.ui files, but not python files?
In my workflow I create ui-file with QtDesigner, then convert it to python using pyuic5.
It is thus a one-way conversion (I then subclass it in another file to avoid my code being overwritten).
How do I make QtDesigner "see" my python code?
Qt Designer recognizes 2 types of elements:
The .ui that are the product,
And the plugins that are the ingredients.
So if you want a widget to be seen in Qt Designer you must create a plugin, if you download the source code in the folder examples/designer/plugins there is an example.
On the other hand there is no converter from .py to .ui since the transformation is not possible in all cases.
I am developing the GUI for my application using wxpython and have most of the features down, except in the main frame/window I want to have a box for choosing a file (in this case, the input will have to be an excel file). Something similar to the standard filebrowser that is accessed whenever you choose "open" from a menu.
Below is an image to show exactly what I want...
You probably want a wx.FileDialog. It provides access to the default file dialog of the OS your app is running in. You can see an example of how it's used in the wxPython demo package. This tutorial also has some screenshots and sample code:
http://www.blog.pythonlibrary.org/2010/06/26/the-dialogs-of-wxpython-part-1-of-2/
The screenshot you show appears to be an interface to actually open the dialog. You can easily create that using sizers and basic widgets. Then just bind the open button to a handler that will show the dialog.
You might also want to take a look at the FileBrowseButton from wx.lib.filebrowsebutton (also in the demo).
There are a few other related widgets which you might be interested in too: wx.DirDialog, MultiDirDialog or wx.GenericDirDialog.
Assuming you know the basics of wxPython you can use wx.GenericDirCtrl and wx.ListCtrl to make nice browser
I am trying to write a custom widget for the Qt Designer using only Python. I was following a couple of tutorials I found online but none of them were working or anything close to what I would call to be a minimum working example.
So my questions are:
What steps are involved to make a a custom widget appear in the Widget Box of Qt Designer?
If you can spare the time: Please provide a minimum working example (like a widget with a label in it saying "A truly minimal working Qt custom widget example").
Or is it maybe not possible at all to include a custom widget using only python?
There are very few examples available on how to make a custom widget in pyqt. I wrote this article with a working example: Making a Custom Widget in PyQt
Here is the answer to your question #3: How do I use promote to in Qt Designer in pyqt4?
I am using PySide and it works the same way. This method works directly with your Python custom widget code. You do not need to write any separate plugin code.
After you have promoted your custom widget, you can right click on it and add your signals with "Change signals/slots..."
I would recommend putting all you widgets in a YourCostumWidgetsPack.UI file, and then when you load this file in Qt Designer, in addition to the UI you are working. It will load all your custom widget information.
I found this article to be your answer: https://doc.qt.io/archives/qq/qq26-pyqtdesigner.html
But, I haven't been able to install it in Qt Designer though :D