PDA

View Full Version : Stylesheet is not working for QToolButton



cob@1988
6th August 2019, 17:01
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);
}
QToolButton:pressed
{
background: transparent;
border: none;
image: url(Skins/lea/fb/delete_all_icon_touch.png);
}

Fareanor
8th August 2019, 13:01
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:


QToolButton
{
border: none;
background-image: url(Skins/lea/fb/delete_all_icon.png);
}
QToolButton:pressed
{
/*No need to repeat "border: none;"*/
background-image: url(Skins/lea/fb/delete_all_icon_touch.png);
}

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).

cob@1988
8th August 2019, 16:01
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:


QToolButton
{
border: none;
background-image: url(Skins/lea/fb/delete_all_icon.png);
}
QToolButton:pressed
{
/*No need to repeat "border: none;"*/
background-image: url(Skins/lea/fb/delete_all_icon_touch.png);
}

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

d_stranz
9th August 2019, 17:09
//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.

Fareanor
12th August 2019, 07:49
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.