Results 1 to 5 of 5

Thread: RollOver on a QtPushButton (or QtToolButton)

  1. #1
    Join Date
    Nov 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default RollOver on a QtPushButton (or QtToolButton)

    I'm trying to make a normal button on Over effect (on qt 4.5) : when you go over a button it switch to a different image, when you leave it it turn back to the normal image.

    i write this lines:
    QToolButton* dice= new QToolButton(this);
    QIcon icon;
    icon.addPixmap(QPixmap("img/gioca_on.png"),QIcon::Active);
    icon.addPixmap(QPixmap("img/gioca_off.png"),QIcon::Normal);
    dice->setIcon(icona);
    dice->setIconSize(QSize(103, 43));
    dice->setGeometry(50, 50, 103, 43);


    probably i don't get at all how to use the MODE parameter on the addPixmap method.
    any suggestion.



    On the same topic, what about if i want to use alpha-png (so with transparence) and don't want to show the normal PushButton Gui under the transparence?

    tnx all

  2. #2
    Join Date
    Jul 2009
    Location
    Italy, Pieve Ligure (GE)
    Posts
    55
    Thanks
    7
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: RollOver on a QtPushButton (or QtToolButton)

    Quote Originally Posted by Snick View Post
    Qt Code:
    1. QToolButton* dice= new QToolButton(this);
    2. QIcon icon;
    3. icon.addPixmap(QPixmap("img/gioca_on.png"),QIcon::Active);
    4. icon.addPixmap(QPixmap("img/gioca_off.png"),QIcon::Normal);
    5. dice->setIcon(icona);
    6. dice->setIconSize(QSize(103, 43));
    7. dice->setGeometry(50, 50, 103, 43);
    To copy to clipboard, switch view to plain text mode 
    Well, assuming "icona" in line 5 is a typo for "icon" (the compiler would catch it anyway), I had some success, using QIcon::addFile() rather than QIcon::addPixmap(). It needs an additional size parameter. The file parameter can be a regular file or a resource. Something like this:
    Qt Code:
    1. QPushButton * pButton;
    2. QIcon icon;
    3. QSize size(MY_BUTTONW, MY_BUTTONH);
    4.  
    5. pButton = new QPushButton("", parent);
    6. pButton->resize(size);
    7. pButton->setIconSize(size);
    8. icon.addFile(strIconNormalFName, size, QIcon::Normal);
    9. icon.addFile(strIconActiveFName, size, QIcon::Active);
    10. pButton->setIcon(icon);
    11. pButton->show();
    To copy to clipboard, switch view to plain text mode 
    I assume it should also apply to QToolButton but I didn't check. However, I run into a problem anyway: if the button has the focus, it is shown with the active image regardless of the mouse position.
    On the same topic, what about if i want to use alpha-png (so with transparence) and don't want to show the normal PushButton Gui under the transparence?
    This seems contradictory: if you do not want the graphics underneath to show through, do not use transparence. Or am I missing something?

    Ciao,
    M.

  3. #3
    Join Date
    Nov 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: RollOver on a QtPushButton (or QtToolButton)

    Tnx you for the quick answer,

    yes icona was a typo for icon.

    regarding the second question, the main problem is: i just want a pushable image that change when you are over it, so at the end seams the quickly solution using the Qtoolbutton or the QPushbutton to doing this.

    sometimes you need to use alpha image on doing this, and if there any way to hide the "normal" background, i can keep using the Qtoolbutton , instead of creating a new class for doing this

  4. #4
    Join Date
    Jul 2009
    Location
    Italy, Pieve Ligure (GE)
    Posts
    55
    Thanks
    7
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: RollOver on a QtPushButton (or QtToolButton)

    I suspect you only have to try (as I still do not understand the need for alpha in this case).

    However, if you have several buttons of that kind, subclassing the Qt class may be easier and lead to cleaner code than repeating a possibly complex customization for each button.

    Wishing you good luck,

    M.

  5. #5
    Join Date
    Aug 2009
    Location
    Greece, Chania
    Posts
    63
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: RollOver on a QtPushButton (or QtToolButton)

    You can reimplement the mouseMoveEvent function and check when the button is hovered. If it's hovered update and in paintEvent function change the icons for the button.
    Misha R.evolution - High level Debugging IDE

    Programming is about 2 basic principles: KISS and RTFM!!!

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.