PDA

View Full Version : File picker



steve38
11th January 2016, 21:32
Hi guys,

Is there a file picker in qt designer ?? click a button and it opens a dialog that allows mw to pick a file to use in some way. I just cant find it maybe ....

Cheers
Steve

anda_skoa
11th January 2016, 22:47
Not in designer, but that can easily be accomplished using QFileDialog in a slot connected to a button.

Cheers,
_

steve38
12th January 2016, 19:06
ok cool .....got it and its now working fine .... better than I expected !!!

so now my file loads great ... what's the best thing to use for a drop down list in qt designer ? i want to be able to display a list of data from the file we just selected ... its door entry data, we just selected the file and now want to select a name from the list created from the file we just chose .

ChrisW67
12th January 2016, 20:13
QComboBox or maybe QListView/QListWidget
http://doc.qt.io/qt-5/widget-classes.html#the-widget-classes

d_stranz
13th January 2016, 04:03
Looking at some of the Qt documentation, examples, and tutorials could save you a lot of time versus asking questions here and waiting for someone to respond. Everything you have asked so far is more than adequately covered.

anda_skoa
13th January 2016, 11:01
Another good starting point when looking for a widget is the widget gallery: http://doc.qt.io/qt-5/gallery.html

Cheers,
_

steve38
14th January 2016, 17:17
OK combobox in and working ... but.... I have two files one with the GUI stuff in it and one with the guts of the program, the main program code starts with -


class MyApp(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)


does it have to start with a 'class' ?? the flow would be easier to control without it... main() doesnt really swwm to do much at all now... all the code seems to need to be in MyApp

d_stranz
14th January 2016, 22:53
I think your "MyApp" class is a bit misnamed. It isn't the app, it is the main window for your app, and derives from QMainWindow and the Ui_MainWindow class (which is automatically generated from the Designer's .ui file - at least that's how it works in C++).

In a C++ Qt app, this class is generally named MainWindow (or in your case, MyMainWindow). A C++ main() creates instances of QApplication and MainWindow, and then calls show() on the MainWindow instance and exec() on the app instance.

steve38
16th January 2016, 08:52
Stupid question I guess but why is it or does it have to be a class... my impression from things I have seen and read is that Class should be used for multiple instances.... there is and will only be one GUI running at once.

anda_skoa
16th January 2016, 09:35
Class has nothing to do with number of instances.

A class defines a custom data type, a combination of data and functions working on that data.

You are creating a subclass, a specialization of an already existing class (QMainWindow)

Cheers,
_

d_stranz
16th January 2016, 18:38
the flow would be easier to control without it

The other thing to understand about Qt is that it is event-driven, like most other GUI frameworks. The control of flow through the program is in the hands of the GUI framework. Your app responds to events generated by the framework, the operating system, the user's actions, and so forth. In Qt, these are mostly divided into two types: events and signals. Things generated by the OS typically come in as the flow would be easier to control without it: paintEvent, mouseMoveEvent, keyPressEvent, etc. and the QWidget class implements default methods to handle them. Things generated by framework objects, like pushbutton clicks, timer timeouts, etc. are presented as signals. In your code, you implement slots to handle them.

So, rather than your app controlling the flow, the Qt framework controls the flow, and your app implements (usually) short pieces of code that get executed in response to them. Nothing in your code executes except the initial startup bits in main() (and the object methods they invoke) until some event or signal occurs that you have written code to handle.

That's why a C++ or Python program written using the Qt framework looks like a bunch of disconnected parts with no logic to hook them together, as opposed to a typical non-GUI program where your main() and the methods it calls control everything. In the Qt case, there is a flow of control, but it is embedded in the Qt event loop instead of main().

I think of event-driven programming as like one of those marble raceways, where a half-dozen marbles are zooming around on different paths at the same time. The "control" is in the mechanism that lifts the marbles up to the starting point and lets them go; the individual raceways ("slots") do something with the marble and eventually dump the marble back at the start and wait for the next one to get dropped.

Boy am I rambling this morning :rolleyes: