QTabBar icon position - c++

Is there a way to change the alignment of the icon or text of a tab in Qt? Specifically, I would like the text to appear below the icon. By default the icon sits to the left of the text, but that's not appropriate for all situations (especially when you start styling your tabs with stylesheets) It would seem very odd to me that this aspect would be so restricted when I can completely alter the look and feel of the rest of the tab.
Thanks for any suggestions!

The only way I can see is to create a subclass of QTabBar that implements your own painting algorithm. Then you'd need to subclass QTabWidget to set your own version of the tab bar. It doesn't look like a lot of fun to me.

Related

How to add QMenus or Qactions on a Widget like QlistWidget area as a list item?

Is there any way to add QActions as a list item on QListWidget?
I want to make a customization window which will show list of actions on a widget for move up, move down, Rename and other options. I'd like to display it on the widget same as it appears as a context menu.
I tried adding it as a list item with icon and text, but the look it not very good:
i) list items with blank icon are not aligning properly, even after adding a blank icon of size 16*16 is not taking up any space and text with icons & w/o icon are not aligning.
ii) I'm unable to add right-pointing black triangle at the right most, in-case of sub-menus cause somehow unicode character for this is not getting displayed on my Linux machine.
That's why I want to add QActions as it are getting popped at original place.
Any suggestions?
Yes I have a suggestion : do not try to make fancy widgets like this, users will not find it intuitive
You should find another way to implement this.
Imo, something like a QToolButton with a QToolButton::MenuButtonPopup popup mode will do the trick. This way, you can embed menu and sub-menus in a widget, using QToolButton::setMenu().

Specific QPushButton style

How can I customize the look of a QPushButton or QToolButton to look something like elementaryos's webpage "buttons"?
All I really want is the characteristic image position and the text on it's side, maybe if i'm lucky i can also get a border like that, but i don't really need the little description below the title :)
Can i do it only with StyleSheets, or do i have to subclass QPushButton/QAbstractButton/Something like that? I already searched everywhere but didn't found that level of customization without things like painting something in a fixed place, which is exactly what i don't want.
EDIT:
I really would like a solution that would get me a customizable button, not a fixed image one, something in the tracks of
MainWindowButton(QString(title), /*opt*/QString(description), QImage(icon));
There are a number of approaches that may work.
You might first consider trying to compose a solution with a normal QPushButton with a QVBoxLayout on it. You could add three QLabels; one for the title text, one for the caption text and one for the image. Some CSS could probably be used to render the background image of the button for up and down and more CSS to style the text in the two labels and position the image on the third but you would then find that the labels don't shift down when the button is clicked.
I think the best solution involves direct painting. You could do this by sub classing a QWidget and overriding the paintEvent(). Render everything for the up state and shift everything over and down a bit for the down state.
You could achieve this without sub classing by rendering the up and down states to a QImage and styling a QPushbutton with them using CSS.
There are a number of combinations of these approaches too.
You can set the background as white with the icon in the right corner with some creative use of the border-image stylesheet property where the bottom border is as tall as the icon and the top, left and right borders are 0 pixels wide. You'll need to make a custom image that basically looks like the icon with a couple pixels width on the left and top that are white
http://doc.qt.digia.com/qq/qq20-qss.html#theboxmodel
The text you may have to do overriding paintEvent.

How to write a scrollable MFC custom control?

I want to write my own chart control which requires scrolling.
I found that there is a CScrollView but nothing like this for a control.
Other toolkits like Cocoa, QT or GTK offer me a base class where i can set a content view which is displayed in a viewport and saves me from writting all of the scrolling code.
The code for custom scrolling isn't that much. Create the scrollbars, write the message handlers and remember one rectangle for the current visible part.
I would just try it. If you have problems, we are here to help :-)

How to prevent an icon being highlighted?

I have a listwidget with items which have icons. When the item is selected both the text and the icon are highlighted. My problem is that when the icon is highlighted it just goes entirely black because I'm using only two colours. Is there a way to prevent the icon from being selected?
You can add additional images to the QIcon, depending on it's state:
QIcon icon(...);
icon.addFile("selected.png", size, QIcon::Selected);
See also the documentation of QIcon::addFile().
Best solution was to make your own qstyle which handled the painting of the backgrounds of listitem sub controls and draw the icons qrect as white
Another possibility would be to reimplement QListWidgetItem... You could therefore have a bigger control on how things gets done during the process of selection and painting...
Of course, it's a lot more work...

Custom dropdown for CComboBox

I'm trying to create a custom dropdown for a derivative of CComboBox. The dropdown will be a calendar control plus some 'hotspots', e.g.
So I figure the best way to achieve this is to have a simple CWnd-derived class which acts as the parent to the calendar control, and have it paint the hotspots itself.
The window needs to be a popup window - I think - rather than a child window so that it isn't clipped. But doing this causes the dialog (on which the combobox control is placed) to stop being the topmost (foreground?) window, leading to its frame being drawn differently:
alt text http://img693.imageshack.us/img693/3474/35148785.png
This spoils the illusion that the dropdown is part of the combobox since its acting more like a modal dialog at this point. Any suggestions on how I make the custom dropdown behave like the regular dropdown?
Are there any other pitfalls I need to watch out for, e.g. focus and mouse capture issues?
When you create your popup window, you need to specify its owner. Owned popup windows will activate their owner when you activate them. Not specifying an owner will cause your window to get activated, which causes the change in the owner you're seeing.
Yeah I had this problem once. A quick google makes me suspect I solved this by using CreateWindowEx() and specifying WS_EX_NOACTIVATE. I have some other code that achieves the same effect by making the window with WS_EX_TOOLWINDOW rather than as a popup window, but I'm not sure of why that was done that way, my intuition would say that making it a popup window would be the way to go.
You can find in the following links two sample project that put in the CComboBox dropdown window a CTreeCtrl or a CListCtrl controls ... similar, you can put whatever you need there. Here is the links:
Tree ComboBox Control
and
List ComboBox Control
I hope this help you.