Results 1 to 5 of 5

Thread: Stylesheet is not working for QToolButton

  1. #1
    Join Date
    Aug 2019
    Posts
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Android

    Default Stylesheet is not working for QToolButton

    Hi Every body,
    I have one issue QToolbutton image is not displaying however functionality is intact.
    I'm trying to apply stylesheet for QToolButton through xml file. Below i've posted the xml snippet. its working fine for windows simulator. but not working for linux/android. Please help me.From code I have checked it seems find from coding.Icons are available in the following location.I have already tried following things.(Note:This is only UI problem from functionality it works fine).This is an inline-delete button.

    1.I have replaced with some other working images which is already visible in some other places.(but here it is not visible)
    2.Change from .png image to some .svg image.
    3.Change background.
    4.Added background color.
    5.Added background image.
    6.The buttons which are not QToolButton and created with some customization picks the image from the same location.

    After analyze these things I am suspecting that somehow QToolButton does not pickup the image or the syntax is not proper.I am using QT 5.
    Any help would be highly appreciated.

    QToolButton
    {
    background: transparent;
    border: none;
    image: url(Skins/lea/fb/delete_all_icon.png);
    }
    QToolButtonressed
    {
    background: transparent;
    border: none;
    image: url(Skins/lea/fb/delete_all_icon_touch.png);
    }

  2. #2
    Join Date
    Aug 2019
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Stylesheet is not working for QToolButton

    Hi,

    You don't need to repeat "background: transparent;" and "border: none;" in "QToolButton:pressed" since they already are specified in "QToolButton".

    Concerning your problem, I think you should not use "image" but "background-image".

    For example:
    Qt Code:
    1. {
    2. border: none;
    3. background-image: url(Skins/lea/fb/delete_all_icon.png);
    4. }
    5. QToolButton:pressed
    6. {
    7. /*No need to repeat "border: none;"*/
    8. background-image: url(Skins/lea/fb/delete_all_icon_touch.png);
    9. }
    To copy to clipboard, switch view to plain text mode 
    Perhaps you'll need to define the properties "height" and "width" to make it properly visible (if the native size is too big for example).
    It should work this way (I hope).
    Last edited by Fareanor; 8th August 2019 at 13:13.

  3. #3
    Join Date
    Aug 2019
    Posts
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Android

    Default Re: Stylesheet is not working for QToolButton

    Quote Originally Posted by Fareanor View Post
    Hi,

    You don't need to repeat "background: transparent;" and "border: none;" in "QToolButtonressed" since they already are specified in "QToolButton".

    Concerning your problem, I think you should not use "image" but "background-image".

    For example:
    Qt Code:
    1. {
    2. border: none;
    3. background-image: url(Skins/lea/fb/delete_all_icon.png);
    4. }
    5. QToolButton:pressed
    6. {
    7. /*No need to repeat "border: none;"*/
    8. background-image: url(Skins/lea/fb/delete_all_icon_touch.png);
    9. }
    To copy to clipboard, switch view to plain text mode 
    Perhaps you'll need to define the properties "height" and "width" to make it properly visible (if the native size is too big for example).
    It should work this way (I hope).

    Thanks for reply.
    I have tried with whatever you said.But still button is not visible.
    I am sharing C++ code snippet so you can get how do I create QToolButton.

    m_pBackspaceButton = new QToolButton(this);
    m_pBackspaceButton->setObjectName(INLINE_BACKSPACE_OBJECT_NAME);
    m_pBackspaceButton->setVisible(false);
    m_pBackspaceButton->setFocusPolicy(Qt::NoFocus);
    m_pBackspaceButton->setAutoRepeat(t rue);

    //piant it inside paint
    void input:aint()
    {
    m_pBackspaceButton->setAttribute(Qt::WA_WState_ExplicitShowHide);
    m_pBackspaceButton->setAttribute(Qt::WA_WState_Visible, false);
    m_pBackspaceButton->setAttribute(Qt::WA_WState_Hidden);

    m_pBackspaceButton->render(&painter, m_pBackspaceButton->pos(), QRegion(), QWidget::RenderFlags(0) /* Don't render children */);

    m_pBackspaceButton->setAttribute(Qt::WA_WState_Hidden, false);
    m_pBackspaceButton->setAttribute(Qt::WA_WState_Visible);
    }

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,136
    Thanks
    235
    Thanked 660 Times in 650 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Stylesheet is not working for QToolButton

    //piant it inside paint
    void input:: paint()
    What is "paint()", and how are you using it? The snippets of code you posted are basically useless, because they give no context about how or where this code is executed.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Aug 2019
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Stylesheet is not working for QToolButton

    It seems that you are trying to render the button by yourself too (your paint() method). I don't think it is compatible with stylesheets.
    I remember reading somewhere in the Qt documentation (I can't find it again) that you cannot combine StyleSheets with other styling method (via QProxyStyle for example).
    This may be the problem.

    If your paint() method is really needed, in this case, I would suggest you to not use stylesheets for rendering the button but using the mouse events instead and use the QToolButton::setIcon() method on mouse pressed and mouse released events.

Similar Threads

  1. QtoolButton stylesheet styling
    By conti in forum Newbie
    Replies: 1
    Last Post: 29th June 2013, 09:13
  2. Problem with QToolButton + stylesheet
    By Bagration in forum Qt Programming
    Replies: 0
    Last Post: 14th December 2010, 04:32
  3. Stylesheet is not working for QToolButton
    By sudhansu in forum Qt Programming
    Replies: 10
    Last Post: 24th March 2010, 08:30
  4. QToolbutton:checked -> QIcon:selected not working
    By tomf in forum Qt Programming
    Replies: 4
    Last Post: 21st March 2010, 21:17
  5. TabOrder for QToolButton not working
    By gren15 in forum Qt Tools
    Replies: 6
    Last Post: 28th May 2009, 16:38

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.