PDA

View Full Version : Make a pushbutton flat but on cursor above it to show that it is a button ?



hakermania
15th January 2011, 10:48
When you make button flat, the border goes away, how can I have this border on mouse above button (so as to show better that it is a button) A good example is VLC preferences: it has flat buttons that show you that hey are buttons by showing their border every time your mouse goes above them.

Thx in advance for any replies
http://img52.imageshack.us/img52/1246/examplei.png

Lykurg
15th January 2011, 11:04
Subclass QPushButton and write your own paint event using QStylePainter. To detect if the mouse is currently over the icon, you can reimp enter and leave event or you can simply use QWidget::underMouse().

tbscope
15th January 2011, 11:54
Bonus tip: VLC is opensource and written with Qt

hakermania
15th January 2011, 13:05
I am trying to figure out how to work with the mouseevent
.h


protected:
void mouseMoveEvent(QMouseEvent *);

.cpp:

void MainWindow::mouseMoveEvent(QMouseEvent *){
if (ui->pushButton->underMouse())
cout << "hello\n";
}
It doesn't work though.. I will check vlc's source as well...

tbscope
15th January 2011, 14:48
I am trying to figure out how to work with the mouseevent
...
It doesn't work though.

The correct way to do this (Object Oriented that is), is to subclass QPushButton and implement the mouse move event function like Lykurg already said.
Use the mouse event for the mouse details.

norobro
15th January 2011, 16:50
You can achieve this using Style Sheets and the ":hover" pseudo-state.