I am trying to get my head wrapped around the QAbstractTableModel and am not quite sure how to get started. I have the following:
Reading from a socket, It returns a bunch of lines of strings - terminated with EOL..
I dump all of this into a QStringList. I then need to parse this line by line to
create my rows and columns of my table. I have written a function to parse the list,
but not sure if I should pass a pointer to the ModelIndex, and build the table , and if
so what does that look like...
Cant really sseem to find an example that is building a dynamic table with multiple
rows and columns that are of unknown size at creation.
A bit confused about how to do this.
Thanks,
Todd
I think what you're looking for is QAbstractItemModel's canFetchMore and fetchMore methods. These are meant for dynamic models (of unknown/large size), and help to inform your attached views that more data is available to display. An example of using this method can be found in the fetchmore example in the Qt examples.
Much more complex examples (using threads, for instance) can be found throughout the Qt codebase:
QFileSystemModel
QSqlQueryModel
QSortFilterProxyModel
Related
I would like to know if there is a way of using the information provided by
the function of the spark api RDD.toDebugString() to a more structured format, so it can be used to automatically get a graphical representation, for example with graphviz.
It seems that there is some activity around this going on:
https://issues.apache.org/jira/browse/SPARK-1015
But I would like to get the info from toDebugString() to a structured format,
and later decide which graph format to use for representation.
toDebugString() internally iterates through the recursive structure of an RDD, building a displayable string.
Instead of making toDebugString() return a more structured output, read its inner implementation (which does rely on structured data), and modify it to save the data the way suitable for you.
You don't have to wait for any issue on JIRA, just DIY :)
A more detailed and formatted visual representation can be seen using the spark UI which run by default on 4040 port.
Here it the screenshot showing all the details:
I am learning Qt5 using PyQt.
My goal is to create a UI with several goals (I will base my need on the screenshot below).
So here are my goals:
My need
Add directories to a list of directories to be scanned (I know how to use QFileDialog.getExistingDirectory for that). For this I'd like to have a "+" button.
When pressed the QFileDialog would open and a new row would be added.
Then I would scan the directory to look for files. It won't be my first implementation but I'd like to have a circular progress bar being displayed during the scan (at the place of the classic progress bar).
When the scan is done, the UI would display the number of files found during the scan. And the progress bar would be replaced by a tick mark icon (not shown on the screenshot...).
At the beginning of each row, I'd like to have a "-" button to delete the row.
My goal is to learn
This is important, I know I am not the first one to have the idea of such a UI.
So I not looking for a third party lib on top of Qt.
My goal is to learn Qt5 (with PyQt) with this example.
But if its unrealistic, please tell me!
My knowledge
Mode View: I implemented some basic model view widgets to display strings, and I understand how to extend the idea to tables or trees.
In this case the number of rows in the table would be handled automatically.
But is it possible to created a table that would display not only strings but also widgets?
Widget Mapper: I read that another methodology is the QDataWidgetMapper. In this case, I would have to deal with creation of news rows by myself, and then I would map data onto them.
But it seems to be a hard and long job.
So, is it a good idea?
So finally could someone tell what is the best direction for that?
I am not looking for code, but since it takes a lots of time to learn new concepts, I'd like to learn and use the correct one before starting coding.
Thank you for your help :)!
After so more searches, I found that I need to use the delegate methodology.
In Qt5 it's QStyledItemDelegate and in Qt4 it's QItemDelegate.
I could find a nice tutorial at the moment, but I started coded it.
I'm beginning Qt/pySide programming and am trying to implement a simple QListView with QFileSystemModel as the model. I have this working and in addition have defined a name filter on the model. I'd like to get a list of all files in the QListView (or rather the underlying model).
The following code appears to do this, but is incredibly ugly and cannot possibly be the correct way. Help!
model = myQListView.model()
idx = model.index(model.rootPath())
for i in range(0, model.rowCount(idx)):
child = idx.child(i, idx.column())
print model.fileName(child)
That is the correct way of working. The whole idea of the QAbstractItemModel abstraction is to provide a unified API for accessing arbitrary and possibly dynamic data which happen to fit into a list, table or tree presentations. Because this API has to accomodate everything from a simple dummy list of a few strings to the contents of an address book, including the rich contact details, it is inherently complex. Depending on what you want to achieve, using a one-purpose tool might be better in your specific situation.
By the way, the QFileSystemModel is very dynamic in nature (the directory enumeration happens on a separate thread). You won't get meaningful data until the directoryLoaded signal is emited, you have to wait for it. If you are simply looking for a list of files to use in your code, using Python's native facilities might be easier.
Good day!
There are instances of classes QListView and QTreeView.
Both of the instances loads data from model (QStandardItemModel).
QTreeView displays positions (For example: Chief, Manager, Developer, etc).
Clicking on the title of position a list of employees revealed.
QListView displays only positions of staff.
Question:
How can I display a full list of names of employees in QListView not showing their positions?
Which methods I need to override?
What can you advise in this situation?
P.S. Thanks!
I don't think you are going to be able to do that with a single model.
This thread suggests using a proxy model to flatten the original one without having to maintain two instances of that data. But the implementation pointed to (KDE's KReparentingProxyModel) isn't exactly trivial.
There is some documentation on proxy models, and the QSortFilterProxyModel might be usable in your context, although I think you'll need something more specific.
You might also find the classes attached to the third response on this thread: ModelView - how to use proxies to filter this data? interesting as a starting point.
(Sorry this isn't very specific. Searching for "qt flatten tree model" will give you other ideas.)
Try to use QListWidget, is easier than QListView.
I'm trying to export an AdvancedDataGrid to CSV. This is easy enough for non-hierarchical data, but when using a HierarchicalCollectionView to show treed data it gets trickier.
Any suggestions on how to access each of the cells just as they appear on screen when all of the nodes are expanded?
If you've expanded all the nodes like you mentioned (you can use the AdvancedDataGrid's expandAll() function for this), you can then run the AdvancedDataGrid through the following CSV export utility class to access each of the cells as they appear on the screen:
https://onyxmueller.net/2011/08/20/advanceddatagrid-csv-export-utility-class/
However, I've found when dealing with a HierarchicalCollectionView as the data provider, that it is better to write some custom logic to "flatten" the data for CSV export.
Hierarchical data doesn't map well to CSV which is essentially flat. You are essentially trying to write nested objects into spreadsheet.
Accessing the data isn't that hard, you can just recursively work through getChildren() in the collection.
The hard bit is writing it into the CSV file in a way that can be retrieved later. The only really good ways of doing this is by ignoring the fact that you are writing to CSV. As soon as you get to the children field of the root object you are going to end up writing some horrible array parsing mechanism.
My solution? Write it out to JSON, and stick it in a single cell of the CSV. You'll save yourself a ridiculous amount of pain in the long run.