So, with
tableWibget->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
my column are resized to content, but that doesn't look good when content is small and grid doesn't fit all the space.
and with
tableWibget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
it fits all the space, but sometimes content of some cell doesn't shown fully.
how can I make something like both above - content must fit all the place in widget, but if some cell can't take all content it resize to fit it all and scroll bar appears
You can set resize mode on column index as below::
headerView->SetResizeMode(0, QHeaderview::Stretch);
headerView->SetResizeMode(1,QHeaderview::Interactive);
Related
I'm trying to fit all widget, I have tree frames:
First frame:
Have a label (that need to have some name with a big letter size)
A custom combobox to change the value of the label if nedded
A button to make the selection of the combobox
Second frame:
Have a treeview with some information that when I make a clic in one row another treeview appears in the 3rd frame. This treeview have occupy all the frame
Third frame:
Have three columns:
The first one have two rows:
Fist row two buttons add and remove, that have occupy all the row.
Second row a treeview that have occupy all it space. This treeview appears when click a row in the first treeview, how can I show the empty treeview and fill in when click the row. The function is OnDoubleClick
The second column:
Have two buttons that have to be in the center of the rows.
The third column:
Same as the first but with other treeview.
Here is an image of what i want to achive:
I'm not going to rewrite your whole program because that's a lot of code, but I'll explain the way I would approach the problem. Tkinter layout is really simple if you are methodical and organized, and try to solve only one problem at a time.
Main layout
First, you seem to have three main sections: a toolbar across the top, a middle section with a treeview, and a bottom section with a whole bunch of stuff. So, first thing I would do is create three frames, one for each section. Then, I would use pack like this:
toolbar.pack(side="top", fill="x")
main.pack(side="top", fill="both", expand=True)
bottom.pack(side="top", fill="both", expand=False)
I don't know if that third section should expand or not. It's not clear what sort of behavior you expect when the user resizes the window.
Toolbar layout
This one is very straight-forward. It's three widgets spread equally. You can use pack or grid, either will work just fine.
Main layout
This just has a treeview, or maybe a treeview with scrollbars? Again, pack or grid works just fine with such a simple layout.
Bottom
This one appears to be made up of three sections: a left section, a middle section, and a right section. Like with the main layout, I would start by creating three frames, all as children of the "bottom" frame created earlier. Then, I would again use pack since it's a simple horizontal layout:
left.pack(side="left", fill="both", expand=True)
middle.pack(side="left", fill="both", expand=False)
right.pack(side="left", fill="both", expand=True)
By setting expand=True to the left and right sides, if the window grows or shrinks, these will grow or shrink too while the middle section stays its natural size.
Bottom-left and Bottom-right
Both of these look identical. It looks like the easiest thing to do would be to create the widgets (ie: no more frames), and then use grid to lay them out. Though, if by "buttons" you mean you could have several, you could create a frame for the buttons so that you can more easily pack all the buttons from left to right.
Bottom-center
You can create buttons that are a child of this frame, and use either grid or pack.
If I set View = Report, then you get a single column and a vertical scrollbar (what I want). However you also get an area at the top reserved for column headings even if you don't have column headings (not what I want).
If I set View = List, then no screen space wasted for column headings (what I want) but there are now multiple columns and a horizontal scrollbar (not what I want).
I think I'd be happy if I could use Report mode but just somehow shrink the space reserved for the column headings to zero. Any ideas?
I think you are searching for CListBox. See here for more.
If you would like to continue with CListCtrl then use List view or Small Icon instead of Report view. For more see here.
I would like the horizontal scroll bar to appear whenever there is text eliding. Such that the user won't have to resize the whole GUI. How would I do this?
This is what I have coded:
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(1,QHeaderView::Stretch);
ui->tableWidget->resizeColumnsToContents();
I also tried enabling scrollbar to appear always, but scrolling to the very right doesn't do anything.
If I set textElideMode to ElideNone , the text from the 2nd column is partially hidden and no scrollbar appears.
QHeaderView::Stretch will stretch the column width to the available space. Use QHeaderView::ResizeToContents to make the column wide enough to display the content, resulting in a horizontal scroll bar if necessary.
This will have a couple of side effects of which I'm not sure you want them.
There will probably be no more ellipsis in the elided text.
If all of the values in your Hash column are very small, then that column will be very thin, so there might be 'empty' space next to that column.
Me need to set up automatic positioning of TextBox in layout (with horizontal and central alignment and resizing).
Docking don't work well, because it don't centering widget at vertical.
Disabling all anchors also work very badly. Look at picture below.
You can calculate every time the ratio between the original state of the form and the actual state of the form handling Resize event of it. This number can be multiplied to the coordinate ( see location ) of the textBox, thus everytime your form is resized, the location of the textbox will stay the same.
Apart from the fact I still can't see why this class fills columns and scrolls horizontally, rather than filling rows and scrolling vertically, I'm confused how the width of items is controlled. I'm seeing quite a lot of padding (50-80 pixels) between the longest item in a column and the next column which means wasted space.
Is it controllable?
Somebody else asked about scrolling, here is the answer.
If you are referring to column width then you can change it using:
CListCtrl list;
list.InsertColumn(0, _T("Column1"));
list.InsertItem(0, _T("Item with a long name"));
list.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);