PDA

View Full Version : Set a ToolButton Hovered



vajindarladdad
11th August 2009, 10:19
Hi all Experts ,
I am developing an application in which I am trying to make it work like MS-Excel .
My problem is , I am trying to set a particular QToolButton hovered on some particular Event.
Is it possible to set a particular QToolButton in hovered state ?
Need help to set a button hovered state.
Just give me a Hint.

wagmare
11th August 2009, 10:21
u mean like this .. u have to change
http://doc.trolltech.com/4.3/stylesheet-syntax.html#pseudo-states

yogeshgokul
11th August 2009, 10:27
Create a QHoverEvent manually and send it like this.

QHoverEvent event(QEvent::HoverEnter, pos, pos);
QApplication::sendEvent(TARGETWIDGET, &event);

vajindarladdad
11th August 2009, 10:27
Hi ,
I have already applied the stylesheets to the buttons & these are working fine when the Button is clicked , hovered , hovered but not Pressed , etc .

My stylesheet is like this

QString styleSheet = QString("QToolButton\
{border: 1px solid %1; background-color: %2; border-radius: 4px;} \
QToolButton:hover:!pressed{border-width: 1px; border-image: url(:/images/RibbonToolButtonHoverBk.png) 4 4 4 4 stretch stretch;}\
QToolButton:hover:pressed{border-width: 1px; border-image: url(:/images/RibbonToolButtonPressedBk.png) 4 4 4 4 stretch stretch;}\
").arg(border.name()).arg(color.name());


these stylesheets are working fine when working with mouse hover , mouse click.
I just want to implement the same with keyBoard usage

wagmare
11th August 2009, 11:49
can u set these stylesheets while keyPressEvent() occurs ..? but i think hover is only used on mouse event ... ! but can u change the pseudo state of button manually ..

vajindarladdad
11th August 2009, 13:02
Hello Sir ,
the Stylesheets are applied to the buttons already & its working fine with mouse events.
My requirement is to change the state i.e. from unselected button to the hovered button without moving mouse over it.
The button should be in hovered state .

In other words , just need to shift focus from one button to another when we press a arrow keys , like we set in other languages like setTabOrder() in HTML , setTabIndex()

yogeshgokul
11th August 2009, 13:04
In other words , just need to shift focus from one button to another
Setting focus is different from hovering. Did you try what I suggested ?

vajindarladdad
1st September 2009, 12:33
Hi All & YogeshGokul,
I tried what you all suggested but it is still not working .
I have attached a trial project in which i have created the object of QHoverEvent & invoking the event.
Please... Please let me know where i am going wrong.

This is the function where i want to make the QToolButton Hovered.


void Widget::keyPressEvent(QKeyEvent *event)
{
QPoint newPos(toolButton->pos().x()+5,toolButton->pos().y()+10);
QPoint oldPos(QCursor::pos());

qDebug("ToolButton Position %d %d",newPos.x(),newPos.y());
qDebug("Cursor Position %d %d",oldPos.x(),oldPos.y());

QHoverEvent *hoverEvent = new QHoverEvent(QEvent::HoverEnter,newPos,oldPos);
QApplication::postEvent(toolButton,hoverEvent);

qDebug("In Widget::keyPressEvent");
QWidget::keyPressEvent(event);
}