What is the proper way to create subtable in a QTableWidget? - qt

I have already implemented a subtable functionality in a QTableWidget. That is, if you click a row that contain a Left Arrow icon, a new row will be added and in there another instance of QTableWidget will be attached using setCellWidget.
All is working fine.. until I need to sort the table in an interval bases: this row that contain subtable, should be kinda sticky to its parent row. But, the sort method made them separate. I browse again the documentation, and I found this : QAbstractItemView#setIndexWidget. I am not sure how to implement this, but it seems like it will make the subtable attached to this row, without the need to add a new row.
Have you face this kind of issue before? Would love to know how you solve it

UPDATE
I think the proper way is indeed to use QAbstractItemView.setIndexWidget: it'll keep the data / model untouched so the rows can be properly sorted. We just have to properly display a new widget that don't override the current data appearance

Related

Ag-grid dynamically span entire row

I have a grid that presents database entities one per row with some crud options (the crud options are icons in their own cells). When the delete button is clicked, the design calls for the entire row to be turned into a confirmation message with buttons to continue or cancel.
Apparently you can give a function for colSpan on each colDef. I tried giving the first colDef a span equal to the number of displayed columns in the case that the row data has a property isDeleting === true, while clicking the delete icon would set the row data's isDeleting property to true.
I was unable to get this to work, and even if I were to get it to work, I'd need to be able to dynamically change the cell so that it contains the confirmation message.
Any help is greatly appreciated.
After a very long day of searching, I found this article on "full-width" rows. You can provide your gridOptions with an isFullWidthCell function, plus fullWidthCellRenderer and fullWidthCellRendererParams properties, and the full width of the row will be populated using the renderer according to the params (as is the case with a cellRenderer in a ColDef)
So, my delete button component can set a piece of data that the isFullWidthCell function can check for, and if it finds it, it will use the cellRenderer provided.
AgGrid seems to have thought of everything.

How to figure out the index of a ToggleGroup's selected toggle?

I'm trying to select an item from a list that's sorted the same way as a ToggleGroup I have besides it. However, I found that toggleGroup.getToggles().indexOf(toggleGroup.getSelectedToggle()) always returns -1 (visible in the IndexOutOfBoundsException thrown as I pass it). Is there another way of figuring out the index, or am I at a loss with my approach and need to figure out something completely different?
UPDATE: Apparently, for the first time an item is selected (I have this code attached to changes of selectedToggleProperty()), it works fine (I just get no notice of it because the elements I make visible have no proper layout). However, when an item is selected while another item already is selected, getselectedToggle() becomes null, causing aforementioned behavior.
All of the JavaFX toggle controls have a property called UserData. You should use that to create the links between the toggles and data list. Relying on the index of the toggles in the toggle group is probably a bad idea.

How can I create a draganddrop wrapper inside a table row, that can represent the whole row

When I use treetable in Vaadin, it is working fine drag and drop the whole row when click the left and right blank ereas. but that is not user friendly, I wanna create a draggable layout inside the row, let's say the 1st component of the each row, that when clicking it, the whole row is selected and can be draged and dropped to reorder.
The thing is I can create a vertical layout with wrapper doing that, but drag mode is only for its component or the wrapper itself, and when doing the drag action, it doesn't actually showing the whole row is moving, which may confuse the clients. What can I do to make it looking like I am dragging the whole row, similar with the one you drag the blank area of each row? Thanks.
I'm afraid there currently is no way for adding a wrapper that would extend the entire row instead of just one cell. To do this you'd need to extend the client-side implementation of Table (VScrollTable) and this is not something I would recommend as it is quite complex.
I do think that what you describe should be possible in core Vaadin (without using drag & drop wrappers), so could you please file a ticket at dev.vaadin.com? And please attach a small application showing the problem to make it easier for us to see the problem and fix it.
Anyways, in order for you to get it working today I'd suggest that you change your UI design a bit and for example borrow drag handles from iOS. By this I mean that you could add an icon that suggests "draggable" as a background-image in the first cell (or in the row header cell of each row) that encourages the user to grab the row there, where it is "empty" and dragging works. This way the user might not be too confused if dragging only works reliably in some parts of the rows.

Displaying QAbstractListModel items in QTableView columns

I've been toying around with Qt and ran into a small issue.
I want to display a list of pictures as a table of icons. Right now, I'm doing this by subclassing QAbstractTableModel, and plugging it into a subclass of QTableView.
This, in my opinion, overly complicates the code, the model and the view (especially when trying to edit/append items). When trying to implement the model as a QAbstractListModel, the items are displayed as table rows.
Is there a way to make QTableView display items as columns, instead?
Edit: Such that the items are rendered in a single row from left to right, and wrapped to a new row.
Or is it preferable to use the table model for table views in any case and work around the issues?
It's worth mentioning I'm using C# bindings for Qt based on Qt Jambi.
The QListView has exactly the functionality you are talking about.
If you don't need any functionality specific to QTableView, then I would suggest switching.
If you set "isWrapping", then the list will start from the top, go down to the bottom, then wrap to a new column.
Set "flow" to LeftToRight to display the list in rows instead of columns
You might also need to set "resizeMode", instead of Fixed, to Adjust. Which will automatically move things around when the list is resized.
Hope that helps.
Just as a side note, here is FlowLayout example. So if you just want to display a set of images in a self-adjusting grid, this would do it for you without all the overhead of a list/table. However, it doesn't give you any selection/editing capabilities or anything just layout.
I don't understand something here. You implement TableModel, so you can prepare data for view in the most desirable way. Suppose you have data A,B,C,D, then you can return A(00),B(01),C(10),D(11), or for example A(00),C(01),B(10),D(11). Is it what you want to do?

how to divide QGridLayout into rows and columns at Design Time in QT?

how to divide QGridLayout into rows and columns at Design Time in QT ?
I want to design one form where i want to have 2 columns and 7 rows .
I am designing using QTCreator but i am not getting any option of giving rows/columns.
It shows only these properties
See Using Layouts in Qt Designer. For you the most important paragraph is this:
The simplest way to manage objects is
to apply a layout to a group of
existing objects. This is achieved by
selecting the objects that you need to
manage and applying one of the
standard layouts using the main
toolbar, the Form menu, or the form's
context menu.
place your widgets on the form
arrange them into 2 columns and 7 rows
select all of them
right click on the selected widgets
select Lay Out in a Grid on the context menu.
You can often drag a new UI element to a position between two existing columns to create a new column - the GUI indicates that it's ready to create a new column by showing a blue vertical line to the user (same thing for creation of a new row with a horizontal blue line).
If instead it is showing a red line or outline, that's indicating that it will fit the element currently being dragged into the existing row/column grid at the indicated position, without creating a new row or column.
It can sometimes be quite difficult to get the GUI to play nice - I've have a number of occasions where I can follow this process to create a new column - but not if I try to place the UI element on the row I actually want it on - so instead I end up dropping it on another row to create the column, dropping another of the same UI element where I actually want it, and deleting the first (superfluous) UI element.
Alternatively, it can quite often be easier to simply right click the element with the layout set, select "break layout" from the layout menu, move things about manually and then go back and select "layout in grid" (or whichever other option) from that layout menu - hoping that it will correctly guess where you want things to go in terms of rows and columns. It's usually pretty good at that.
But yes, it probably would be nice to be able to force create a new column/row in a grid layout (perhaps with some default UI element - a label, maybe - inserted as a placeholder to keep the new row/column open) at a predefined position within the grid for those times when the GUI just does not want to play nice.
QLayout structure is created dynamically as you add widgets to it, there's no way to predefine how many rows/cols a layout have.
Maybe you are using the wrong approach to achieve your goal.

Resources