Discussion:
Interesting problem with properties.
(too old to reply)
Igor Mironchik
2015-05-23 11:00:19 UTC
Permalink
Hi,

I have class NavigationButton that derived from QAbstractButton.
NavigationButton redefines property QString: text.

In my application I have one such button and initialize it with the
following code:

sendButton = new QtMWidgets::NavigationButton(
QtMWidgets::NavigationButton::Right, QObject::tr( "Send" ), q );

First setText() invokes with "Send" text from constructor of
NavigationButton, it's normal. But I have second invoke with "&Send".

What is the problem can be?

Bellow stack trace of the second invoke:

0 QtMWidgets::NavigationButton::setText navigationbutton.cpp
147 0x424ae3
1 QtMWidgets::NavigationButton::qt_metacall
moc_navigationbutton.cpp 148 0x42ed6a
2 QMetaProperty::write(QObject *, QVariant const&) const
0x7ffff65d7b60
3 QObject::setProperty(const char *, QVariant const&) 0x7ffff65ffca3
4 ?? 0x7fffe70792ed
5 ?? 0x7fffe707a95b
6 ?? 0x7fffe7611723
7 ?? 0x7fffe76127ae
8 QMetaObject::activate(QObject *, int, int, void * *) 0x7ffff65fd01a
9 QTimer::timerEvent(QTimerEvent *) 0x7ffff660af12
10 QObject::event(QEvent *) 0x7ffff65ff189
11 QApplicationPrivate::notify_helper(QObject *, QEvent *)
0x7ffff76af2b4
12 QApplication::notify(QObject *, QEvent *) 0x7ffff76b2c86
13 QCoreApplication::notifyInternal(QObject *, QEvent *)
0x7ffff65cae24
14 QTimerInfoList::activateTimers() 0x7ffff6624a54
15 ?? 0x7ffff6624cfd
16 g_main_context_dispatch 0x7ffff52cfc3d
17 ?? 0x7ffff52cff20
18 g_main_context_iteration 0x7ffff52cffcc
19
QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)
0x7ffff6625643
... <More>

And again: second invoke receive "&Send" as argument. From where this
"&" appears?

Thank you.

P.S. In my code there is no setText() invokes...
Matthew Woehlke
2015-05-27 19:07:15 UTC
Permalink
On 2015-05-23 07:00, Igor Mironchik wrote:
> I have class NavigationButton that derived from QAbstractButton.
> NavigationButton redefines property QString: text.
>
> In my application I have one such button and initialize it with the
> following code:
>
> sendButton = new QtMWidgets::NavigationButton(
> QtMWidgets::NavigationButton::Right, QObject::tr( "Send" ), q );
>
> First setText() invokes with "Send" text from constructor of
> NavigationButton, it's normal. But I have second invoke with "&Send".
>
> What is the problem can be?

Interesting; something decided that your button should have an
accelerator? What platform are you on? (If Linux, what DE?)

--
Matthew
Igor Mironchik
2015-05-27 20:29:11 UTC
Permalink
Hi,

27.05.2015 22:07, Matthew Woehlke пишет:
> On 2015-05-23 07:00, Igor Mironchik wrote:
>> I have class NavigationButton that derived from QAbstractButton.
>> NavigationButton redefines property QString: text.
>>
>> In my application I have one such button and initialize it with the
>> following code:
>>
>> sendButton = new QtMWidgets::NavigationButton(
>> QtMWidgets::NavigationButton::Right, QObject::tr( "Send" ), q );
>>
>> First setText() invokes with "Send" text from constructor of
>> NavigationButton, it's normal. But I have second invoke with "&Send".
>>
>> What is the problem can be?
> Interesting; something decided that your button should have an
> accelerator? What platform are you on? (If Linux, what DE?)

This problem appears on Linux Kubuntu 15.04. On Windows 7 I didn't see
this problem.
Koehne Kai
2015-05-27 20:41:14 UTC
Permalink
>>> sendButton = new QtMWidgets::NavigationButton(
>>> QtMWidgets::NavigationButton::Right, QObject::tr( "Send" ), q );
>>>
>>> First setText() invokes with "Send" text from constructor of
>>> NavigationButton, it's normal. But I have second invoke with "&Send".
>>>
>>> What is the problem can be?
>> Interesting; something decided that your button should have an
>> accelerator? What platform are you on? (If Linux, what DE?)

>This problem appears on Linux Kubuntu 15.04. On Windows 7 I didn't see
>this problem.

This is most likely then the KDEPlatformTheme plugin messing with your texts.

See e.g. https://bugs.kde.org/show_bug.cgi?id=337491 . It doesn't seem like KDE considers this a problem ...

Regards

Kai
Igor Mironchik
2015-05-27 21:23:43 UTC
Permalink
Hi,

27.05.2015 23:41, Koehne Kai пишет:
>>>> sendButton = new QtMWidgets::NavigationButton(
>>>> QtMWidgets::NavigationButton::Right, QObject::tr( "Send" ), q );
>>>>
>>>> First setText() invokes with "Send" text from constructor of
>>>> NavigationButton, it's normal. But I have second invoke with "&Send".
>>>>
>>>> What is the problem can be?
>>> Interesting; something decided that your button should have an
>>> accelerator? What platform are you on? (If Linux, what DE?)
>> This problem appears on Linux Kubuntu 15.04. On Windows 7 I didn't see
>> this problem.
> This is most likely then the KDEPlatformTheme plugin messing with your texts.
>
> See e.g. https://bugs.kde.org/show_bug.cgi?id=337491 . It doesn't seem like KDE considers this a problem ...

Thank you. Now I can sleep peacefully :)

But that KDE doesn't consider this a problem is a problem :)

It's seems that I have to implement more smart painting and hide this
"&" sign...

Thank you again.
Matthew Woehlke
2015-05-27 21:36:45 UTC
Permalink
On 2015-05-27 17:23, Igor Mironchik wrote:
> 27.05.2015 23:41, Koehne Kai пишет:
>>> sendButton = new QtMWidgets::NavigationButton(
>>> QtMWidgets::NavigationButton::Right, QObject::tr( "Send" ), q );
>>>
>>> First setText() invokes with "Send" text from constructor of
>>> NavigationButton, it's normal. But I have second invoke with "&Send".
>>>
>>> What is the problem can be?
>>
>> This is most likely then the KDEPlatformTheme plugin messing with your texts.
>>
>> See e.g. https://bugs.kde.org/show_bug.cgi?id=337491 . It doesn't seem like KDE considers this a problem ...
>
> Thank you. Now I can sleep peacefully :)
>
> But that KDE doesn't consider this a problem is a problem :)
>
> It's seems that I have to implement more smart painting and hide this
> "&" sign...

No... well, depending on what you mean by "smart". If you are doing
custom text painting for a widget, you should be handling the '&' as an
accelerator indicator (which is what it is). Note that there is logic in
QPainter::drawText() to do this for you. In particular, see the
Qt::TextShowMnemonic flag. (Exact methods may vary if you are drawing
via QStyle, but you should still be able to tell whatever you are using
to paint to render mnemonics / accelerator indicators as such.)

If you are rolling your own text rendering, then yes, you should
explicitly ignore the character yourself :-), or better, paint it
properly. (If you think you might need to care, note that "&&" should be
rendered as a single '&'.)

--
Matthew
Continue reading on narkive:
Loading...