I have add a font awesome user icon in an element. When I hover on that element I want the icon size to be decreased thoroughly. So I have used transition as "all 0.5s ease". It works but it animated step wise. Can it possible to animate the icon smoothly.
The problem you have is that as the text reduces in size, so does the hover target, which means the text can reach a point where you are no longer hovering and so it starts to grow again. This is likely to cause a nasty visual jaggy effect.
In the below example, the first example uses "focus" which isn't affected by the change in size. The second uses "hover", which is highly likely to be affected.
Click or tab onto example one and it will resize smoothly. Try to hover on example two and it will be horrible.
You can solve this by having a hover target that remains a constant size, so isn't reduced during the animation.
Other common causes for jagginess in this particular area (resizing text) are:
If the browser struggles to render the font during the resize
If the before and after sizes are not far apart and the animation has a long duration
If the before an after sizes are very far apart and the animation is has too short a duration
div {
font-size: 5em;
transition: font-size 0.5s ease;
}
div:focus {
font-size: 0.5em;
}
p {
font-size: 5em;
transition: font-size 0.5s ease;
}
p:hover {
font-size: 0.5em;
}
<div tabindex="0">
Example One
</div>
<p>
Example Two
</p>
Related
Whenever I set the groove of my QSlider to an image (as an image or background-image) or background-color (but not color) I am unable to drag it, but only move it by clicking on the slider to step it. Here is my current stylesheet for reference, this is being set via a call to setStyleSheet()
fanSliderOnStyleSheet = "QSlider {padding-left: 80px; padding-right: 80px;} \n"
"QSlider::handle:horizontal{image: url(:/images/FanSlider/blowerSw2.png); padding:-65px; }\n"
"QSlider::groove:horizontal{background-image: url(:/images/FanSlider/barind.png);}\n";
If i comment out the line that sets the groove the slider works as intended so I've eliminated any other variables of the slider I can think of.
Note: I prefer setting it as a background-image over image as it maintains the true size if I do it this way.
Does anyone have any idea on how to fix this, or is it by chance a bug with Qt? I've been banging my head against the wall on this for the past couple days and my searches haven't revealed any useful information.
The padding is too high for your handle: if you set a value higher than the size of the image in the groove property, it will interfere with the handler movements (the grab section would be empty).
I get exactly the same problem when I set an image with a width to 100px and a padding property to 110px.
Remove the padding and it should be OK:
fanSliderOnStyleSheet = "QSlider {padding-left: 80px; padding-right: 80px;} \n"
"QSlider::handle:horizontal{image: url(:/images/FanSlider/blowerSw2.png);}\n"
"QSlider::groove:horizontal{background-image: url(:/images/FanSlider/barind.png);}\n";
How do I get rid of grey area as seen in the image below. It seems like if the table does not fill the entire space, the grey color just extends until the end.
I coded something similar to this image in C++.
It's not just grey color, it's a vertical header. As I see it, your options are:
Get rid of the header in Designer and create your own column with numbers, not editable, of course
Use custom stylesheet for QHeaderView, like (example, don't know your preffered colors)
QHeaderView::section
{
background-color: transparent;
color: black;
font: 10pt "MS Shell Dlg 2";
}
It works with QTableView.
UPD: Try the following: set the stylesheet for QHeaderView AND it's sections if needed, like
QHeaderView
{
background-color: white;
}
This will paint your header white, no grey, like you wanted. Then you can improve the stylesheet, styling sections (probably, you'll like proper borders and all, so don't use "border: 1px solid balck", play with border-top and/or border-bottom, otherwise sections will get ugly double inner borders).
After that you can consider styling only one header or both, further improve styleshhet, but the point remains that QHeaderView and it's sections can be styled independently
My widget structure is as follows:
QToolBar with a QTabBar added to it and a QToolButton added after the TabBar.
By default, there will only be one tab open, and the ToolButton functions to open more tabs. (Like the tab interface for Google Chrome)
The problem I run into is that when there is only one tab, the TabBar allocates more space than necessary (looks like: size_of_tab(0) * 2) When I add extra tabs, the button aligns nicely with the TabBar, but as soon as I close them down to only 1 tab there is extra space again.
I have tried messing with the horizontalSizePolicy and programmatically setting the width, but neither worked.
Any ideas would be appreciated.
Try setting the style-sheet of the QTabBar::tab as follows, before doing this remove all the changes you have in the code which affect the tab size. You cab adjust 100px value to suit your requirement.
QTabBar::tab
{
min-width: 100px;
max-width: 100px;
}
I have a number of QToolBar's in Qt::TopToolBarArea of my QMainWindow. I want to remove the left and right borders from the ones which are not on the edges. However, when try the following code, it ends up erasing ALL of the borders on the QToolBar:
toolBar2->setStyleSheet("QToolBar { border-left-style: none; border-right-style: none; }");
I want this to appear as one continuous tool bar, with no borders between them. What is the proper way to achieve this?
You're right, styling one or more of the borders (including removing it) ends up removing the rest. This is because style sheets and Qt Styles don't mix very well, and the Qt Style usually loses.
What you can do is bring back the borders you do want to see. This example specifies how the top and bottom borders should appear, which in turn removes the left and right boders:
toolBar2->setStyleSheet("QToolBar {border-bottom: 2px solid black; border-top: 2px solid black;}");
I have a problem with QTabBar/QTabWidget. This is what my program looks like at the moment, using QTabBar:
As you can see, there is an unsightly line between the QTabBar and the QScrollArea underneath it. This line is part of the frame of the QScrollArea, which I can't simply get rid of, because it is required on the other three sides. I realise I could use QTabWidget, but then I would have to create a widget for each tab, which is not feasible here: the contents of the QScrollArea change according to the selected tab, but there is only one QScrollArea widget. (Duplicating it each time a new tab is created would cause its own problems.)
So does anybody know a way to either:
(i) tell the QScrollArea to draw a frame without the top line; or
(ii) use the same widget for each tab in a QTabWidget?
Update 3 For another approach, see my answer below.
Update 1 I have implemented zvezdi's suggestion, and the unsightly line has disappeared:
This is an improvement. But it's not right. Look at the gaps between the scroll bars and the border. On the right, it's two pixels instead of one; on the bottom, it's three pixels. And the gap on the right between the QScrollArea border and the mainWidget border is one pixel too big. This is due to QTabWidget's border style, which I am losing my sanity trying to change. If I say:
MyTabWidget -> setStyleSheet ("QTabWidget::pane { margin: 0px,0px,0px,0px }") ;
then the margins seem to be right, but the borders disappear:
If I say:
MyTabWidget -> setStyleSheet ("QTabWidget::pane { "
" margin: 0px,0px,0px,0px;"
" border: 1px solid darkgray;"
"}") ;
then I'm almost back to where I started:
If I try to remedy this with:
ApplicationTabWidget -> setStyleSheet ("QTabWidget::pane { "
" margin: 0px,0px,0px,0px;"
" border: 1px solid darkgray;"
" border-top: 0px;"
"}") ;
then again I am mocked for my pains:
Update 2 If I forget setStyleSheet and just turn documentMode on, this is what I get:
Please somebody, tell me I'm being stupid, and there's a perfectly simple solution to all this.
You said "the contents of the QScrollArea change according to the selected tab" well if I assume that this is not true, and what you mean is that the content of the widget that is inside the scroll area changes, then you can try this:
Make as many QScrollArea objects as many tabs you need in your QTabWidget, but only one, for example QTextEdit, which you will show in every scroll area, and which content will change on tab change (takeWidget() from the old tab's QScrollArea & setWidget() on the new tab's QScrollArea)
I don't know how you've designed your code, but to try my suggestion your code should be designed around the widget inside QScrollArea, rather than the QScrollArea itself.
Unless I misunderstand, if you turn off the QScrollArea's border by setting the frameShape to NoFrame, the tab widget still has its frame lines on the sides and the bottom where you want them.
I have tried another approach: Use QTabBar, as in the first screenshot, and then change the style for MyScrollArea (obvious, in retrospect):
MyScrollArea -> setStyleSheet ("QScrollArea {"
"border: 1px solid #898C95;"
"border-top: 0px;"
" }") ;
This is the result:
Almost right! There are three problems:
- the little square at the intersection of the two scroll bars is missing its bottom border (but it gets drawn if I click on the scroll bars, or resize the window, or the main window loses focus);
- the colur #898C95 is hard-coded, so it won't be right if the user changes the style. But if I leave out the border style, then the whole border is painted white. Is there a way to query the current border colour of a style?
- most seriously, the background colour of the breakpoint widget on the left-hand side is not white any more.
But I think I've wasted enough time on this! I will stick with this solution unless anybody can suggest something else to try.