Results 1 to 8 of 8

Thread: How to find hovering on Dynamic Button

  1. #1
    Join Date
    Jul 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default How to find hovering on Dynamic Button

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to find hovering on Dynamic Button

    So what did you do so far to solve your problem?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to find hovering on Dynamic Button

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to find hovering on Dynamic Button

    Did you try searching the docs for "hover"?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jul 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to find hovering on Dynamic Button

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to find hovering on Dynamic Button

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    May 2010
    Posts
    15
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default Re: How to find hovering on Dynamic Button

    why dont you use css for this?....when you crate the button add:
    Qt Code:
    1. button->setStyleSheet(tr("QPushButton{}"
    2. "QPushButton:hover{}"
    3. "QPushButton:pressed{}"));
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jul 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to find hovering on Dynamic Button

    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());
    }

    }

Similar Threads

  1. Mouse hovering or press event not working?
    By qtzcute in forum Newbie
    Replies: 11
    Last Post: 15th July 2009, 10:53
  2. Custom widget: a button within a button
    By Gnurou in forum Qt Programming
    Replies: 7
    Last Post: 18th June 2009, 09:03
  3. hovering problem in QGraphicsItem
    By wagmare in forum Qt Programming
    Replies: 4
    Last Post: 13th March 2009, 17:31
  4. dynamic widgets
    By sonu111 in forum Newbie
    Replies: 1
    Last Post: 13th December 2008, 12:59
  5. QWhatsThis appear when hovering over QPushButton?
    By seanmu13 in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2007, 20:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.