QTableWidget show scroll bar - c++

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.

Related

How to collapse Gtkmm notebook tabs?

So I am making a Gtkmm application using a Gtk::notebook and during run-time I'm adding new tabs to the notebook. But when I add more tabs than there is space on my screen it just keeps going moving out of the screen.
Now I know most Gtk widgets have a lot of properties that can be configured, so I'am wondering is there such a property for notebook that automatically collapses tabs or scales them in some way to make it fit inside the widget/screen.
If not it would be great if you could give me some pointers to how to implement this functionality myself.
set_scrollable() is your best bet. It will add scrolling arrows on the sides of the tab labels at the top when there isn't enough room to show them all.
Note that GtkNotebook will always ask for enough space to show the contents of all tabs, not just the one that's currently visible. If one of your tab pages is really big (say, contains a 10x10 grid of 100x100 buttons), you won't be able to resize the GtkNotebook smaller than that tab page (in that case, 1000x1000 + the height of the label area), even if the current tab page is just an empty container. All set_scrollable() will do is let you resize smaller than the width needed to show all tab labels at the top.
Put this in your .xml GUI file in the GtkNotebook object:
<property name="scrollable">True</property>
This causes the tabs that go out of screen to be horizontal scrollable by adding arrows beside the last tab at the right and the most left tab at the left.

Set horizontal scroll of CListBox row back after resetting content

I got a multiple selection CListBox with horizontal scroll bar enabled and showed correctly. Problem is, that when I use function
lst.ResetContent() and fill it back, I can't find way to scroll text in the rows back to the same position. I tried to use
lst.SetScrollPos(SB_HORZ, horizScroll, TRUE); , where horizScroll = lst.GetScrollPos(SB_HORZ); This works correctly on scroll bar itself, but
text in the row stays not scrolled (manual scrolling functions OK).
Structure of my program is:
CListBox lst;
int horizScroll;
/*Periodically doing code bellow*/
//Get current scroll position
horizScroll = lst.GetScrollPos(SB_HORZ);
//Reset current content
lst.ResetContent();
//Add item into CListBox (UNICODE in my application)
lst.AddString(L"Some longer text then width of CListBox");
//Calculate horizontal extent and set it through
lst.SetHorizontalExtent(calculatedWidth);
//Try to scroll text (scrolls only scroll bar, not text itself)
lst.SetScrollPos(SB_HORZ, horizScroll, TRUE);
UpdateData(FALSE);
Thanks in advance!
EDIT:
As "rrirower" answered correctly,
lst.PostMessage(WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, 250), 0);
message does the job. Scroll position from horizScroll works perfectly. I suggest posting this message twice, because if you do it only once, text is re-scrolled visually from beginning to the wanted position. When you post it twice, text visually stays at the correct position and scroll bar just quickly comes to the right place.
If I understand you correctly, you're trying to scroll the text in the list box horizontally using the program code. If you use Spy++, you'll see that when you manually scroll, using the mouse, a series of WM_HSCROLL messages is posted to the list box control. You can accomplish the same thing by doing this...
lst.PostMessage(WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, 250), 0);
You need to calculate the position (I used 250 above), but, the above code should move the text and the scroll bar horizontally.
After some reading it seems that Invalidate should do the trick. Since as I understand you have one text line this should be fine, however if the painting itself is complex and requires resources you can use ScrollWindowEx and then InvalidateRect on the rectangle returned by the latter to repaint only the changed area.

CListCtrl: single column without column headings?

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.

Dynamically adjust the width of combobox so the entire string can be shown

I am using a combobox control to show names stored in a database ( I need to preserve space, that is why I use it instead of a listview, for example ).
My problem is that sometimes text is longer than the combobox so part of it can not be seen.
Is there a way to resize combobox' listbox so it can entirely show text, or at least to enable some kind of horizontal scrolling so the user can scroll to see the entire text?
Looking through combobox documentation, I haven't found any style that can solve my problem. Trying to add WS_HSCROLL as a style in my CreateWindowEx call didn't help either.
Thank you.
You are looking for the CB_SETHORIZONTALEXTENT message.
An application sends the CB_SETHORIZONTALEXTENT message to set the width, in pixels, by which a list box can be scrolled horizontally (the scrollable width). If the width of the list box is smaller than this value, the horizontal scroll bar horizontally scrolls items in the list box. If the width of the list box is equal to or greater than this value, the horizontal scroll bar is hidden or, if the combo box has the CBS_DISABLENOSCROLL style, disabled.
Parameters
wParam
Specifies the scrollable width of the list box, in pixels
lParam
This parameter is not used.

Wrong stem position in balloon-style tooltips in report list-view

I'd like to change the default style of the list-view control's tooltips to balloon.
I first called ListView_GetToolTips() to get the HWND of the list-view's tooltips control, and then used GetWindowLongPtr()/SetWindowLongPtr() to add the TTS_BALLOON style.
I handle LVN_GETINFOTIP to customize the tooltip for the items (first column) in the list-view: the tooltip texts that appear for the first column items are actually a copy of the text of the third column. The other columns (subitems) are managed automatically by the list-view.
The balloon-style tooltips for the first column items seem OK; their stems are correctly positioned:
But the tooltips for the second column seem drawn wrongly, e.g. the balloon is drawn as if it was referred to a subitem in a row below the actual row pointed by the mouse cursor.
In the following picture, the "star" indicates the position in which the mouse cursor was when the tooltip appeared, but the tooltip's stem points to a row below, marked with an ellipse:
The strange thing is that the tooltips for the third column seem drawn correctly.
Is this a bug in the list-view control? (I'm using Windows 7.)
Or what am I missing here?
The ListView uses a tracking tooltip and positions it to unfold and reveal the hidden text in a column that's too small. It's not expecting its tooltip to be a balloon and so doesn't compensate for that.
You'd need to sub-class the tooltip itself, watch for TTM_TRACKPOSITION messages from the ListView, and adjust the coordinates.
Your second question - the shaded background comes from the system theme. You should be able to get it by calling SetWindowTheme on the tooltip (I'm not sure why the ListView disables themes for the tip).