PDA

View Full Version : How to find hovering on Dynamic Button



vims1611
13th July 2010, 20:59
I am new to Qt.Please help me in animating button on hovering. I have some sets of dynamic buttons created according to the option selected from list box. Now I want to show animation on the button image when I hover on it.

Each button has the objectname as the file path of the image on the button. Now when I hover on them, I need it to read from the same file path and show animation on the button :o

wysota
13th July 2010, 21:53
So what did you do so far to solve your problem?

vims1611
14th July 2010, 21:34
I tried making an event , but still trying to figure out how to use the event create to the dynamic created button :( . enterEvent and LeaveEvent is working with the static button in the form.

wysota
14th July 2010, 22:34
Did you try searching the docs for "hover"?

vims1611
14th July 2010, 23:37
Well i solved dat problem....

for(int i=0;i<file_names.count();i++)
{

if(file_names[i].contains("init"))
{
event_class *pb1 = new event_class(this->ImageTabWidget);
pb1->setIconSize(resultSize);
pb1->setFixedWidth(70);
resultImage = QImage(resultSize, QImage::Format_ARGB32_Premultiplied);
loadImage(sub_dirc_name+"/"+file_names[i], &sourceImage[i], pb1);
gLayout->addWidget(pb1,row_count,col_count,0);
action_buttons<<pb1;

pb1->file_path=QString(sub_dirc_name);
pb1->p_b=pb1;

action_buttons[direct_count]->setObjectName(sub_dirc_name+"/"+file_names[i]);
textEdit1->append(sub_dirc_name+"/"+file_names[i]);
connect(action_buttons[direct_count], SIGNAL( clicked() ), this, SLOT( doSomething() ) );

.................................................
}
Wen the mouse moves on the first button, it wokrs fine with enter and leaveEvent but wen i move the mouse on the second button.. it makes de changes to first nd second. :confused:

wysota
15th July 2010, 00:17
I have no idea what your snippet has to do with your problem but I really suggest you type in "hover" in the index tab of assistant and click on Qt::WA_Hover.

Hardstyle
15th July 2010, 08:58
why dont you use css for this?....when you crate the button add:


button->setStyleSheet(tr("QPushButton{}"
"QPushButton:hover{}"
"QPushButton:pressed{}"));

vims1611
24th September 2010, 08:25
The project was stopped but now ctnd. . Thanks for the sugesstions, I got it by creating n event class. Now , I am trying to read a folder and show image on the button as animation. When the mouse runs on the button, it will read the pics from the folder and show one by one, but i am not able to do that in while or by timer..



void sleep(unsigned int mseconds)
{
clock_t goal = mseconds + clock();
while (goal > clock());
}

event_class::event_class(QWidget *parent) :
QPushButton(parent)
{
p_b=0;
}

void event_class::enterEvent(QEvent *e)
{
QDir directory(file_path);
QStringList file_names = directory.entryList(QDir::Files,QDir::Name);


pos=p_b->geometry();
int count = 0;
while(count<file_names.count())
{

QPixmap* pixmap = new QPixmap();
pixmap->load(directory.absoluteFilePath(file_names[count]));
QIcon icon(*pixmap);
QSize iconSize(pixmap->width(), pixmap->height());
this->setIconSize(iconSize);
this->setIcon(icon);

sleep(50);
count = (count+1)%(file_names.count());
}

}