I am currently developing an app using Qt's MVC approach. I have a StandardItemModel which i use to populate the tableview. My tableview has 2 columns. In the first column I obtain the data from the model. Now in the second column I want to show a pushbutton when the user hovers the first column.
I want the button to be row specific. i.e., when the user hovers over the cell(0,0), the pushbutton is shown in the (0,1) cell. Similarly I want to do it for all the rows in my tableview.
As far as i know, there are two approaches, Delegates & setIndexWidget.
I tried using QStyledItemDelgate and was not successful. setIndexWidget leads to performance issues as my tableview has a large data set.
Any code sample or idea of how to go about it would be really helpful.
Related
I'm writing an business application that imports bank statements and allows the user to categorise entries. Once they have done this they can preview their tax statement such as below:
This is currently a gridpane with each cell containing a vbox containing a label and textfield. I don't like it. Its bulky & inflexible.
Each cell is a unique calculation or sum and I'm finding it difficult to get a layout/grouping that I am happy with. I'd like to add descriptive notes adajecent to some cells but this could/would throw the layout out.
I thought about setting specific cells in a tableview like this table:
but seeing this thread How to set value to cell in TableView in javafx and the comment
In JavaFX you generally don't set the values cell by cell like that.
I'm wondering what would be best practice? It seems a bit short sighted that tableviews cannot be used to present (non uniform) non-jpa data.
Update My current work in progress alternative solution is shown in the table above populated by a small class with 3 variables (category, amount and description). Seems better practice.
My application is a tool library manager. It has a treeview containing a list of lists and tools. It also has a tableview showing a list of tools.
When I click on a list in the treeview, I want to show the tableview with the list of children. When I click on a single tool in the tree, I switch widgets and display the editform for the tool.
How do I limit the tableview to only the children of the selected node in the treeview?
My data model is a custom qAbstractItemModel.
I have a similar situation (not quite the same!) as yours. Before I share my experience, my assumption is that you have a database of sorts which consists of the items that make up your lists/tools.
One possible solution is to create two custom models, one for the tree view (say, MyTreeViewModel -> QAbstractItemModel, associated with QTreeView) and one for the table view (MyTableViewModel -> QAbstractItemModel, associated with QTableView).
The two custom models should be fed by the same agent working with the database. The key difference is that the tree view model works with the entire database, and the table view model with only a subset, that is, the children of the chosen item in the main list. Think of it as full mapping v. partial mapping of the database.
When the user clicks on the top list of nodes in the tree view, you can emit a signal which could be picked up by MyTableViewModel, populates with only the children, and is displayed by QTableView.
Because the same agent serves both models, you should be able to maintain data integrity, in the sense changes to the underlying data by one model should be reflected in the other model. This solution has worked out really well for my application. Hope this works for you too!
I'm not sure if this is a complete answer to my own question but I'm much closer. On the tableview I can call setRootIndex() and pass in the current item from the qTreeView. This works to show only the children of the current tree item in the table list.
For me, it still shows both tools and child lists, which I want to filter, but I think that's a different issue.
I have these messages received on the can bus which need to be displayed on a suitable Qt Widget (Please refer attached picture). It seems I can use QTreeView for it.
I need to show a tree which contains many messages as shown in attached picture. Each row will contain information about the received message.
It should consist of columns :
Length
Time of receiving
Message ID
Name of the message
Message content
and when I expand message it should its different signals.
How can I make a QTreeView with columns ?
There is a problem that won't allow you to make what that screenshot shows, and it is that first and second level tiers don't have the same columns layout. AFAIK, it's not possible to do that with QTableView or QTableWidget current implementations and you will have to implement your own class.
If you can adapt to having the same column layout for both levels, then keep reading what I wrote before taking another sight to your screenshot:
You can, QTreeView is only a QTableView with some art for first
column.
Add all the columns you want to your model. A simple
[QStandardItemModel][1] would suffice to do something like the
screenshow
Just remember 2 things:
Only first column item childs will be displayed.
First column cannot be hidden.
[1]: http://qt-project.org/doc/qt-4.8/qstandarditemmodel.html
Introduction: I'm using java, oracle, flex, blazeDS etc. The part of the DB that is relevant to the task i am trying to accomplish is illustrated in the image below:
The Task table will also have a field called enabled , which i forgot in the figure below :) This field is used to enable some of the tasks based on various criteria, when an admin user presses a "Generate task list" button in the GUI.
Based on this generation of the task list, the users in the system should see a grid as the one displayed in the figure below :
This task list should display all the enabled task as illustrated above. The first three columns are retrived from the Task table in the DB, while the next columns(Column_4....Column_N) are generated based on the number of users in the User table. These columns should display the users alias. Each user is part of a UserGroup(Group), which i will model in either a separate table or in the User table itself, as illustrated in figure 1. The Numbers in the grid are based on the Time field in the Task_User table, while the first row below the users shows the sum of the times for each user.
Question: Im still learning Flex, and looking for every help i can get on accomplishing my goal :) I figure i have to implement a datagrid with dynamic columns. But how will the dataprovider work in this scenario? For each enabled taskid the grid has to fill the right user columns with time values. Any tips/help would be much appreciated! It is also important that loading this grid doesnt take to long :)
Is it possible to get horizontal and vertical text in the grid(like shown above)?
I am trying to drag and drop hierarchical data in the same advanced data grid, and I would like the data provider to updated when the ADG is updated. (I want to be able to save and load this tree, so it is important that drags and drops are saved.)
I have a sample application (with view source enabled) posted here: www.crcarlson.com/adg/AdvancedDataGridDragAndDrop.swf
The sample app has an ADG showing hierarchical data as well as flat data. The first column of each datagrid shows the rowindex of the underlying data.
If you rearrange the items on the left ADG, the row indexes become unordered. If you click traceTree you see that the data provider is not in order.
On the other hand if you do the same on the right, the row numbers stay ordered even when the objects move around and if you click traceFlat, the data provider is in the order shown on ADG
My goal is to have the data provider order match the ADG order for the left grid which is displaying hierarchical data.
I would appreciate any advice on this, including "you can't get there from here, do it this way."
I noticed a few things while perusing your code and using the app:
Use an ArrayCollection instead of Array as the dataProvider for a view component whose data changes. This might solve your update problems.
If implementing an ArrayCollection doesn't completely solve your update problems, add the necessary logic to a dragDrop or dragComplete event handler.
I get a runtime error every time I drag an item from adg to adgFlat.
Here's Adobe's take on Using Drag and Drop. Specifically check out the last page titled "Moving and copying data". Good luck to you.