GTK Treeview fixed width - c++

I have a window structured in the following manner:
Window>VBox>Scrolled Window>Tree View>Columns
My issue arises when I label the last column (it must be a dynamic assignment). If the label winds up being too long, the containing window gets stretched horizontally. Instead, I would like a scroll bar to appear at the bottom of the Scrolled Window to deal with it, leaving the window at its original width.
However, it looks like the closest I can come is fixing the height of the Tree View. Surely there's a way to fix the width?

Do you have some code to look at? I have done this many times in python and never had any trouble. Also, you link to the fixed height property of the Tree View rows, you actually need the requested width property of the scrolled window. That link also has a link to set the size of the window.

Related

Sizing of Qt Dialog Window Refusing to Change

I am trying to change the size of a QT dialog window from within the .ui file. The preview of the window in my .ui looks like this.
However, when I run my program, it ignores the sizing policy I have imposed on the window. And it looks likes this :
I have changed the size Policy to minimum (rather than my usual Fixed) for everything within the window just to check. But it seems there is some kind of margin at top and bottom that I am unable to get rid of no matter what changes I make.
The topmost QDialog layout has 0 margin everywhere, so it can't be that.
Here is the hierarchy.
And also the relevant properties for the top most layer: ClickThresholdDlg.
Any tips on what it could be much appreciated. Could it be caused by parts of the GUI further down into the hierarchy ? All of the layouts of 0 margin, and the heights for each is the minimum before it starts cutting off text.

Making UWP ComboBox exceeding parent windows

My app needs to be small in nature so I make it 500 x 100 px in size.
The problem is the ComboBox selection items are also squeezed into that small window size. Of course, I can scroll it, but it doesn't feel right this way.
Here is the picture:
Is it possible to expand the ComboBox selection list so that it exceeds the parent window? Preferably in XAML if possible
Is it possible to expand the ComboBox selection list so that it exceeds the parent window?
No, this is impossible in UWP apps. While using ComboBox class, it displays the drop-down list in PopupRoot, which is a layer has the same view port as its parent window. Anything outside this view port will be clipped, users can't see them. For example, following is a normal ComboBox:
After I give a Margin="-20,-30,0,0" to the drop-down list, it looks like
The part outside the window is clipped.
Besides, The implementation of ComboBox will also make sure the ComboBox's selection list won't exceeds the parent window. The selection list's max height is calculated at runtime, it will be always less than the parent window's height and we can't change its value manually, so it is not possible to expand the ComboBox's selection list.
It's not possible, but you can extend your page to the title bar to have at least some additional space using CoreApplicationViewTitleBar.ExtendViewIntoTitleBar property.
Take a look here and here. (I know the examples are written in C# but it should be similar in C++)

QScrollArea vertical sizePolicy - Fit contents up to maximum height

I've had a real challenge getting QScrollArea to take the minimum space possible up to a maximum height.
My GUI model is as follows: A QScrollArea contains a vertical layout which is populated with a widget of class TableRow. I want this class TableRow to take up the minimum height possible. It has a widget at the top which is always visible, and a QScrollArea below which has a label inside it whose visibility can be toggled. The label is for notes which may be 0 characters or may be infinite in length (hardware limitations aside).
I've found that for a label in class TableRow setting the vertical sizePolicy to Fixed will actually take up exactly how much it needs to fit all the contents (see: Qt Layout, resize to minimum after widget size changes). However this doesn't appear to work with QScrollArea. In fact every sizePolicy I've tried keeps the QScrollArea at a fixed height; except for Ignore, but then the QScrollArea goes to a height of 0, regardless of its contents.
I've created a git branch producing a simplified version of this problem.
Here is the result of applying a fixed vertical sizePolicy:
What I'm expecting from this test case:
The first widget's height should be almost 30px (the height of the upper widget) only showing the borders for the QLabel and QScrollArea
The second widget's height should be shorter than 130px (the maximum height of the QScrollArea being 100px) but large enough to show the label without scrolling
The third widget's height should be 130px, and the scrollbar should appear (this part is correct in every case I've tried except for when the vertical sizePolicy is set to Ignored )
I understand I may need to override some things to make this work, as by itself it's not obvious why a QScrollArea's height might be dependent on its child widgets (which is probably why it was not designed to make this easy, or at least it seems like it wasn't).
However, I think the case I'm trying to make is common enough, and my current approach is justifiable. If there's another/better way to make an individual widget scroll after it reaches a maximum height I'm open to that as an answer, provided it meets the three conditions I'm expecting.
This feels more like a hack than a solution, but it does work for me, at least in the short term. Because the text for lblNotes does not change runtime, I was able to add the following code in the constructor of my TableRow widget:
// Hack to resize QScrollAreas
ui->lblNotes->adjustSize(); // Otherwise lblNotes will think its height is still ~0px
int height = ui->lblNotes->height() + 12; // Borders and margins add up to 12px
if (height > 100) { height = 100; } // Cap the height at desired maximum value
ui->scrollArea->setFixedHeight(height);
Should I have to deal with the case of dynamically set text, I could wrap this in a function to be called anytime the text of lblNotes is set.
I'm still open to solutions that involve using the layout features Qt has natively as I believe that would be preferred if a solution exists. Some QScrollArea contents may not be as straight-forward to determine the height from in the future.

CListCtrl: How to maintain scroll position?

I have a CListCtrl (report style) where I clear the list and repopulate it at certain times. I'd like to maintain the vertical scroll position when doing this. I see there are a couple methods that look promising:
EnsureVisible()
GetScrollPos()
SetScrollPos()
GetScrollInfo()
GetTopIndex()
Scroll()
I'm trying GetScrollPos() and then SetScrollPos() but it doesn't appear to be working. What is the simple correct way to save a scroll position and then later restore it?
UPDATE
Actually it seems I can get to save the scroll position GetScrollPos() and then SetScrollPos() to restore it, however it literally just seems to set the scroll bar position and does not actually scroll the items of my CListCtrl.
UPDATE 2
The Scroll() method seems to correctly scroll the scrollbars and the contents. However it takes a CSize object as it's argument. So the question would be how to translate between the CSize and the output of either GetTopIndex or GetScrollInfo/Pos.
I've done that in the past. IIRC, the trick consisted in:
int topIndex= m_List.GetTopIndex();
RenewContents();
m_List.EnsureVisible(m_List.GetItemCount() - 1); // Scroll down to the bottom
m_List.EnsureVisible(topIndex);// scroll back up just enough to show said item on top
Another way to do it is like so:
CRect r;
m_lcList.GetItemRect(0, r, LVIR_BOUNDS);
int scrollPos = m_lcList.GetTopIndex() * r.Height();
RenewContents();
m_lcList.Scroll(CSize(0, scrollPos));

In Qt, how do I make a dialog un-resizeable, yet automatically adjusting its size to the contents?

I have an instance of QDialog, populated by widgets using code generated by uic. The dialog contains a few labels laid out vertically, and I am popping the dialog from time to time to show some text in these labels. The text can be multi-line and its length is not pre-determined. I set the vertical size policy to fixed, so the user can't drag it (doesn't make sense), but I also want the dialog to change its size before being shown to accomodate for the current size of the labels.
To this end, I was calling QWidget::adjustSize() on the QDialog before displaying it, but it doesn't work as expected. When the dialog is shown, it seems to retain the (wrong) size from the previous displaying, but when I click the mouse in the (disabled) vertical resize mode, the dialog suddenly "snaps" to the (correct) adjusted size.
Is there any way to make my dialog appear correctly?
EDIT: I tied rubenvb's advice, and ended up with this:
QSizePolicy free(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
QSizePolicy fixed(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
dialog->setSizePolicy(free);
dialog->adjustSize();
dialog->setSizePolicy(fixed);
dialog->show();
Unfortunately, that didn't seem to change anything.
This isn't the answer you're hoping for, and it may not apply to what you're trying to do, however, the only way that I was able to adjust the dimensions of a QWidget at run-time was by handling the object's resizeEvent(..) method. This allowed me to calc the size of items based upon the font being used, number of lines, available space, etc., and then adjust their size accordingly before passing the 'event' on to the base resizeEvent(..) method.
My approach used a single QWidget container within a window, below a header, above a footer status area, and to the right of a column of menu buttons. The widget container, inside the resizeEvent() call, would look at the objects it was going to display, calculate the font heights being used, and then resize some items according to their dimensions (because of how the style sheet selected fonts and colors, etc) and then adjust the sub-widget dimensions before allowing the container widget to get the resizeEvent() message.
So I wasn't so interested in setting a window size, but I think the container QWidget might work the same way? I was more interested in setting the dimensions to some asthetically pleasing size, depending upon the dimensions of the display.
Hope you find that helpful.
Do everything in the right order:
Dialog is not shown. Dialog is resizeable.
Calculate new size, set new size.
Set dialog to not-resizeable.
Show Dialog.
Hide dialog, go to step one.