View Full Version : How to create a mouse offer effect for pushbuttons??
athulms
14th September 2011, 11:57
How can i provide mouse over effect to all the pushbuttons in my mainwindow??
FelixB
14th September 2011, 12:10
use stylesheets:
setStyleSheet(QPushbutton:hover{background-color: red;});
athulms
14th September 2011, 14:32
i have already used stylesheet background image fro button. I just want to bounce or zoom the button a little on mouse over
FelixB
14th September 2011, 15:43
it was just a demonstration how to use the ":hover"-property. you can define anything you want... larger text, other border color, other text color, other margins etc...
athulms
14th September 2011, 15:48
ui->pushButton->setStyleSheet("hover{background-color:red};");
I have used the code in my constructor. even if it doesnot work??
wysota
14th September 2011, 15:59
It is :hover, not hover.
athulms
15th September 2011, 05:40
it worked for me sir, thanks
Added after 23 minutes:
i works when i have not provided any style to the button.
But i need the mouse over effect on button with a stylesheet already set. I mean i have a button with stylesheet
ui->playButton->setStyleSheet("background-repeat:no-repeat; background:none; background-image: url(Yellow/M_playUp.png); border:none;");
i have to provide a border to the button during mouse over. I used the code
ui->playButton->setStyleSheet(":hover{border:black};");
but the codes doesnot work
Lykurg
15th September 2011, 08:41
Dear, watch the syntax and have a look at the docs: QWidget::setStyleSheets() overwrites the existing one. So either set all at once or append it. Therefore see QWidget::styleSheet() and QString::append().
athulms
16th September 2011, 13:49
ui->pushButton->setStyleSheet("background-image:url(c:/M_aboutUp.png);:hover{background-image:url(c:/M_aboutDown.png)};");
I have used the above code but no background or mouse over effect appears.
When i use 2separate stylesheet codes second style works. But overwrites the first code.
Lykurg
16th September 2011, 14:34
Again: SYNTAX! wrap the first statement into a QPushButton block.
wysota
16th September 2011, 15:22
Or a "*" block.
athulms
19th September 2011, 05:47
can u pls give the full linecode syntax
ui->pushButton->setStyleSheet("QPushButton:{background-image:url(c:/M_aboutUp.png)};:hover{background-image:url(c:/M_aboutDown.png)};");
I used this an again no change
FelixB
19th September 2011, 08:29
I'd suggest reading this (http://doc.qt.nokia.com/latest/stylesheet-syntax.html)
Lykurg
19th September 2011, 08:30
AAAhhhh! Come on! Watch the css syntax. Take any css guide and see how the basic syntax is. Even the part of the Qt documentation is enough. Just read it. If you can't manage to look that up, you definitely won't be able to use Qt at all, since there, you also have to use the documentation...
athulms
20th September 2011, 05:14
thanks i got it
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.