Is there an easy way to make a collapsible QWidget? - c++

Often on web pages, there are whole areas that contain content that can be reduced to only the title. Is there a way to achieve the same with a QWidget?
For a very simple example of this functionality, see the screenshots here. Of course, the contents should be any QLayout, and thus arbitrary.

You can use the QToolBox widget:

Related

Add some text to a QToolBar

I am having trouble adding some text in a QToolBar. I can only add Actions. Also I have two actions with their rerspectives icons in my QToolBar but I want to separate them and I canĀ“t either.
My newbie approach was to add empty actions to simulate blank spaces between the icons. But the user can click on the blank spaces.
I am using the Design function of QT Creator. Some help would be really apreciated.
It looks like you can't do it from within Designer:
https://bugreports.qt.io/browse/QTBUG-1267
That's an oooold suggestion, too, with a low priority to boot, so it probably won't get fixed any time soon.
You can get your hands dirty and do it in code, however.

Implement as custom widget or try to reuse QListWidget?

I'm creating a control that can be used for manual inspection of Tesseract-OCR's output.
Currently I've implemented it as a custom widget, where I do all the drawing (I use a QScrollArea to handle the scrolling at least), and it looks like this:
As you can see, the images are "flowing", like word-wrapped lines in a text editor, and I use the space below the header text, so I don't have 2 clearly separated columns.
Now, it was suggested to me that using a custom widget is 'reinventing the wheel', but the problem is, I don't see a clear way to customize one of the existing container widgets enough to look and behave like this, that would involve significantly less effort or code. Neither is it clear at all to me what is the best way to do it. At most, I can think of using a QListWidget with owner-drawn items and variable item heights.
Am I wrong to use a custom widget here?

CTreeCtrl - only use checkboxes for certain rows/children

I have a CTreeCtrl and I filled it with content. Now I wanted to add checkboxes but JUST for certain ones. I've found the possibilty to activate checkboxes on the TreeCtrl with m_Tree.ModifyStyle(0, TVS_CHECKBOXES), but this adds a checkbox on each node/child on the whole Ctrl. Is it possible to turn this feature on, but just for certain ones?
All I found is the possibility to add three different pictures, catch the clickevent on a node and change the image. Is there an easier way? Let me know.
Thanks a lot,
jntme
I don't think that CTreeCtrl provide any method to add check boxes at specified node only.
Easiest way to do this is explain in following link.
http://www.tech-archive.net/Archive/VC/microsoft.public.vc.mfc/2005-10/msg00454.html.
please go through and let me know if you are facing problem.
You may be able to accomplish what you want with a custom draw tree control. But, you'll need to render the image states yourself. That could get messy because you'll need to account for all of the possible different states.

Help with this design issue

I'm making a game GUI API. It is coming along very nicely except for one aspect. I want themes similar to how GTK works. The way I want it to work is that every GUI element will have a default Windows9X-like way of drawing themselves. If it is found that a theme is set for that type of widget, it will be drawn with those bitmaps.
My original concept was to create a Theme class which would have getters and setters for the bitmaps.
for example:
themeManager.setButtonHover(Bitmap *bitmap);
The problem with this, is that it is not flexable if I want to create new types of Widgets. I may eventually want to create a superButton which would use a different theme than a button. This is the flaw with that concept. The concept I'm thinking of going with is that each widget type has static methods to set the theme for itself and the constructor uses that.
Are there better ways of doing this that I'm not thinking of? Since it is an API, I want to avoid reading text files, so reading the theme from a text document is not an option.
Thanks
May be template the superButton on a policy and then have a default policy which does the default and the user has the option of providing a different policy? The policy could then define the attributes of the button (such as the hover image etc.) - does what I describe make sense?

Qt: How to show icon when item selected

I have a QListWidget containing items which have icons and when the items are selected the icon is just highlighted out. Is there a way to prevent this? I can't use stylesheets because it's for an embedded application and including them takes up too much space.
thanks
I suppose when you say "Highlithed out", you mean that the icon colors don't render well when the line is selected, and therefore, you can't see properly the icon...
Maybe you could consider using a different icon when the item is selected. It's possible to do so by specifing a mode to your icon.
Example :
QIcon MyIcon(":/images/foo");
MyIcon.addFile(":/images/bar", QSize(...), QIcon::Selected);
You can easily make a try in QtDesigner and see the results...
Hope it helps a bit !
Certainly, drawing on a black-and-white screen presents its challenges.
It sounds like you just want to change the appearance of the interface, not any functionality. If this is the case, a QItemDelegate-derived class (or QStyledItemDelegate) is almost certainly what you want. In particular, the drawDecoration function looks like it is used to draw an icon, and the style options should include whether it is selected. The simplest fix would be to override that function, set the selected flag in the options to false, then pass it up to the parent's function.