Is it possible to style individual tab bars? - qt

I would like to style individual tabs of the tab bar of a QTabWidget (not hover or current but an individual one) WHY? because I need to get the user's attention so that he knows urgent information appeared in that tab. There can be multiple tabs that need attention.

You would have to assemble your own tab widget but i think if you subclass QTabBar and use setTabButton(int index, ...) you can set a custom widget for the item in the tab, this would let you control the behaviour and you could change it through code or style it via the property selector e.g.
QTabBar MyButtonWidget[showalert=true]
{
background-color: red;
}

This seems a little strange. Why don't you start with that tab selected?
I don't think you can do that with stylesheets. You can easily customize first and last but not any tab (AFAIK)
http://doc.qt.io/archives/4.6/stylesheet-reference.html
On the other hand you can set custom icon to draw attention or use void QTabBar::setTabTextColor ( int index, const QColor & color )

You might want to try simply using stylesheets to directly style a tab instead of subclassing just for that purpose. In the stylesheet, you can use the :tab subcontrol to access a single tab, and you can then modify a dynamic propoerty to set its state as either needing attention or not, and applying the style based on the dynamic property.
See : :tab sub control , Customizing using dynamic properties

Related

How to bind display menuitem to a static text

I am trying to create a form, which can mimic the functionality of an area page, at least it should display links to other forms (if categorization cannot be done) how can i achieve it?
Can i bind a menu item to a static text?
Create Tab within form
change Style to FastTabs
change Width to Column width
change Height to Columnt height
Add TabPage to Tab
Drag MenuItem to Tab (or add MenuItemButton)
change Style to Link
XPO: AreaPageSimulation
I resolved this by using .net's link label, unfortunately did not see Matej's answer, but will give it a try when I will actually build this for client, here is what I created:

Editable QTabWidget

I want that user could rename tabs: clicking on current tab label should turn on editable mode.
The only way I can see is to use stacked layout + scrollarea + custom widgets + stackedwidget.
Can I do it with standard QTabWidget?
And one more question. Can I create custom pseudo states (like predefined :hover, :selected etc)?
You can reimplement QTabWidget to get access to QTabBar and use QTabBar::setTabButton method. But sometimes it is difficult to adjust position of inserted widgets ;)
You can't create custom states, but you can use custom properties. See Q_PROPERTY macro and related QSS syntax. Note, that styles will not updated on property change, so you should manually call polish/unpolish to force widget to use QSS.

How can I customize the appearance of the actions in my QToolBar?

I have just changed some toolbars from Q3ToolBars (with QToolButtons explicitly added to them) into Q4 toolbars (with actions added to them straight away instead.)
The old tool buttons had a nice outline around them, but this is not displayed in the new version; the QActions in the Q4 toolbar just look like a line of icons. Is there a way to change the 'button' style in the new version (assuming these actions can be considered as such) and give them the outline? I've looked through the QToolBar reference, but the toolButtonStyle() function only appears to work with whether you want to display icon, text, etc.
...Or will I have to just make actual tool buttons and/or QPushButtons and use addWidget()?
The widget associated with a given action is accessible through QToolBar::widgetForAction (since Qt 4.2). So, you can pass your actions to this method, get the QWidgets returned by it, convert them to QToolBar, and handle them like you normally would (code not tested):
// ...
auto toolButton =
static_cast<QToolButton *>(
m_ui.toolbar->widgetForAction(m_ui.my_Action));
// Will make the toolButton always appear raised:
toolButton->setAutoRaise(false);
// ...
As far as I've been testing, some methods might not work (i.e., QWidget::hide), so do your own testing.
Yes, of course you can edit look of QToolButtons in two different ways:
You can set it style sheet using void QWidget::setStyleSheet(const QString &)
You can reimplement QToolButtons class with new paintEvent function where you will be able to exactly set how your button should looks like.

Customizing the checkboxes of the items of a QTreeView

I'm having the following situation: I need to create a custom tree control, whose checkboxes are also customized. I have easily made most of the customizations for the tree control by using style sheets; I have succeeded adding checkboxes to the QTreeView's items, but I'm having big problems with customizing them - I need to display a custom image for the checked state, and another for the unchecked state.
The place I concluded this can be done is in my subclass of QStyledItemDelegate, in the paint event (i.e. CheckBoxItemDelegate::paint). What I need is to display the text, the icon, and the checkbox for the item. But the problems are:
- I can't get the style of the item (which I set using the stylesheet) - otherwise my text can be drawn with the incorrect color;
- I don't know the rects of each subitem (the checkbox, the icon, the text);
- I don't know how to get the icon of an item (given its QModelIndex) to draw it.
P.S. I had subclassed the QTreeView (obviously), and, as I am working with QFileSystemModel, I have subclassed it too in order to add the checkbox functionality to it.
Can anybody help me, please?
Is QStyledItemDelegate::paint the proper place for changing the visuals of the checkbox of the tree items? If yes, can you please give me a small example or something, how I can do that?
This is how I rendered checkable items inside a QTreeView with two images (eye opened/eye closed, to represent their visibility state) instead of a checkbox:
ui.myTreeView->setStyleSheet(
"QTreeView::indicator:unchecked {image: url(:/icons/eye_grey.png);}"
"QTreeView::indicator:checked {image: url(:/icons/eye.png);}"
);
Items should be set as checkable, of course. Hope this helps.

Flex: Modify an embedded icon and use it in a button?

Just that, if you embed an icon:
[Embed(source='icons/checkmark.png')]
private static var CheckMark:Class;
You end up with a dynamic class. You can pretty easily assign the icon to a button at runtime by calling the setStyle method:
var btn:Button = new Button();
btn.setStyle("icon", CheckMark);
But what if you wanted to alter the icon at runtime, like changing it's alpha value or even redrawing pixels, before assigning it to the button?
So far I can't find a satisfactory answer...
This is the only answer I could find that seemed close: Dynamic Icons (example with View Source)
His solution involves a custom "DynamicIcon" class which is used in the button's icon setting, and a custom Button class which adds one method to the Button class to draw dynamic icons.
The end result is that you are able to send BitmapData to the DynamicIcon class, which will show up in the button. So, embed your image, instantiate your asset class, get the bitmapasset and modify it however you need to and send the bitmapData to the icon.
It's an interesting problem and it seems like there should be an easier solution, but this works without a lot of hassle.
The way I'd solve this is to implement a programmatic skin class that draws the icon itself manually. There's probably more work you'll have to do to ensure the button calculates the correct size as if it has an icon even though it doesn't. You may have to poke through the Button source code to look at how the reference to the icon is stored.
I love just creating programmatic skins that do exactly what I want and then using interesting CSS declarations to modify states - for instance:
button.setStyle("customIconAlpha", .4);
and then of course the skin or the custom button class would have:
var alpha:Number = getStyle("customIconAlpha") as Number;
(not sure if you have to typecast that one)
The big problem I found with programmatic skins is that the button refuses to measure the width/height. I easily got around this by overriding the get methods for each:
override public function get width():Number { return WIDTH; }
override public function get height():Number { return HEIGHT; }
In my case I needed to modify buttons in a TabNavigator, hence no easy way to subclass the button. Thankfully, the parent of each skin is the button, so using static methods within your skin, you can identify the instance of the Button to which the icon skins belong.
If you're using the cover-all "icon" style, a new skin object will be created for each state. So you'll need to keep this in mind when changing the state of the icons.

Resources