How can i provide mouse over effect to all the pushbuttons in my mainwindow??
How can i provide mouse over effect to all the pushbuttons in my mainwindow??
use stylesheets:
setStyleSheet(QPushbutton:hover{background-color: red;});
i have already used stylesheet background image fro button. I just want to bounce or zoom the button a little on mouse over
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...
I have used the code in my constructor. even if it doesnot work??Qt Code:
ui->pushButton->setStyleSheet("hover{background-color:red};");To copy to clipboard, switch view to plain text mode
athulms (15th September 2011)
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
Qt Code:
ui->playButton->setStyleSheet("background-repeat:no-repeat; background:none; background-image: url(Yellow/M_playUp.png); border:none;");To copy to clipboard, switch view to plain text mode
i have to provide a border to the button during mouse over. I used the code
Qt Code:
ui->playButton->setStyleSheet(":hover{border:black};");To copy to clipboard, switch view to plain text mode
but the codes doesnot work
Last edited by athulms; 15th September 2011 at 04:40.
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().
Qt Code:
ui->pushButton->setStyleSheet("background-image:url(c:/M_aboutUp.png);:hover{background-image:url(c:/M_aboutDown.png)};");To copy to clipboard, switch view to plain text mode
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.
Again: SYNTAX! wrap the first statement into a QPushButton block.
can u pls give the full linecode syntax
Qt Code:
ui->pushButton->setStyleSheet("QPushButton:{background-image:url(c:/M_aboutUp.png)};:hover{background-image:url(c:/M_aboutDown.png)};");To copy to clipboard, switch view to plain text mode
I used this an again no change
Last edited by athulms; 19th September 2011 at 05:04.
I'd suggest reading this
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...
thanks i got it
Bookmarks