DevHeads.net

setWindowIcon for QDialog

Hi,

in LabPlot we have couple of modal dialogs, created on the heap and shown with
dlg->exec(). The dialog icon is set in the constructor of the dialog via
QDialog::setWindowIcon(), e.g.
setWindowIcon(QIcon::fromTheme(QLatin1String("labplot-worksheet")));

The icon is set/handled by the window manager if I understand this correctly.
With kwin, the specified icons are not shown and I always get the default
application's icon shown. On windows, this seems to work and I see the proper
icons in the dialogs.

I tried to quit the event loop with

QTimer::singleShot(0, this, [=] () {
setWindowIcon(QIcon::fromTheme(QLatin1String("labplot-worksheet")));
});

in order to call QDialog::setWindowIcon() after QDialog::show() but this
doesn't help.

So, what is the proper way to set the icon that would work everywhere?

Thanks and Regards,
Alexander

Comments

Re: setWindowIcon for QDialog

By Aleix Pol at 03/04/2019 - 09:45

On Sun, Mar 3, 2019 at 11:00 AM Alexander Semke <alexander. ... at web dot de> wrote:
Adding kwin in case they know.

Aleix

Re: setWindowIcon for QDialog

By david at 03/04/2019 - 10:08

On Mon, Mar 4, 2019 at 1:49 PM Aleix Pol < ... at kde dot org> wrote:
Not shown where exactly?
Also X or xwayland?
Does running xprop and clicking on the window show the correct icon?

Aw: Re: setWindowIcon for QDialog

By Alexander Semke at 03/04/2019 - 12:39

<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>
<div>not shown in the window bar, left to the window title. Please check the attached screenshots. On windows the proper icon is shown, on linux/kwin the applicaion icon is used.</div>

<div>&nbsp;</div>

<div>It&#39;s X. The output of xprop:</div>

<div>
<div>_NET_WM_ICON_NAME(UTF8_STRING) =<br/>
_KDE_NET_WM_DESKTOP_FILE(UTF8_STRING) = &quot;org.kde.labplot2&quot;<br/>
_KDE_NET_WM_COLOR_SCHEME(STRING) = &quot;/usr/share/color-schemes/BreezeHighContrast.colors&quot;<br/>
XdndAware(ATOM) = BITMAP<br/>
_KDE_NET_WM_USER_CREATION_TIME(CARDINAL) = 2840133529<br/>
WM_NAME(STRING) = &quot;Import Data to Spreadsheet or Matrix&quot;<br/>
_NET_WM_NAME(UTF8_STRING) = &quot;Import Data to Spreadsheet or Matrix &mdash; labplot2&quot;<br/>
_MOTIF_WM_HINTS(_MOTIF_WM_HINTS) = 0x7, 0x26, 0x1e, 0x3, 0x0<br/>
_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_DIALOG, _NET_WM_WINDOW_TYPE_NORMAL<br/>
_XEMBED_INFO(_XEMBED_INFO) = 0x0, 0x1<br/>
WM_CLIENT_LEADER(WINDOW): window id # 0x5000008<br/>
WM_HINTS(WM_HINTS):<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Client accepts input or input focus: True<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Initial state is Normal State.<br/>
_NET_WM_PID(CARDINAL) = 29202<br/>
_NET_WM_SYNC_REQUEST_COUNTER(CARDINAL) = 83886351<br/>
WM_CLASS(STRING) = &quot;labplot2&quot;, &quot;labplot2&quot;<br/>
WM_PROTOCOLS(ATOM): protocols&nbsp; WM_DELETE_WINDOW, WM_TAKE_FOCUS, _NET_WM_PING, _NET_WM_SYNC_REQUEST, _NET_WM_CONTEXT_HELP<br/>
WM_NORMAL_HINTS(WM_SIZE_HINTS):<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; user specified location: 819, 262<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; user specified size: 536 by 711<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; program specified minimum size: 522 by 711<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; window gravity: Static</div>

<div>&nbsp;</div>

<div>&nbsp;</div>

<div>P.S.: sorry for html and for the full-quote, writing from the web-frontend...</div>
</div>

<div>&nbsp;
<div name="quote" style="margin:10px 5px 5px 10px; padding: 10px 0 10px 10px; border-left:2px solid #C3D9E5; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div style="margin:0 0 10px 0;"><b>Gesendet:</b>&nbsp;Montag, 04. M&auml;rz 2019 um 15:08 Uhr<br/>
<b>Von:</b>&nbsp;&quot;David Edmundson&quot; &lt; ... at davidedmundson dot co.uk&gt;<br/>
<b>An:</b>&nbsp;kde-devel &lt;kde- ... at kde dot org&gt;, &quot;Kwin, NET API, kwin styles API, kwin modules API&quot; &lt; ... at kde dot org&gt;<br/>
<b>Betreff:</b>&nbsp;Re: setWindowIcon for QDialog</div>

&gt;<br/>
&gt; &gt;<br/>
&gt; &gt; Hi,<br/>
&gt; &gt;<br/>
&gt; &gt; in LabPlot we have couple of modal dialogs, created on the heap and shown with<br/>
&gt; &gt; dlg-&gt;exec(). The dialog icon is set in the constructor of the dialog via<br/>
&gt; &gt; QDialog::setWindowIcon(), e.g.<br/>
&gt; &gt; setWindowIcon(QIcon::fromTheme(QLatin1String(&quot;labplot-worksheet&quot;)));<br/>
&gt; &gt;<br/>
&gt; &gt; The icon is set/handled by the window manager if I understand this correctly.<br/>
&gt; &gt; With kwin, the specified icons are not shown<br/>
<br/>
Not shown where exactly?<br/>
Also X or xwayland?<br/>
Does running xprop and clicking on the window show the correct icon?</div>
</div>
</div>
</div></div></body></html>

Re: Aw: Re: setWindowIcon for QDialog

By Martin =?ISO-88... at 03/05/2019 - 13:21

Hi Alexander,

according to the xprop output the _NET_WM_ICON property is not set. The
method inside Qt responsible for this is:
<a href="https://code.woboq.org/qt5/qtbase/src/plugins/platforms/xcb/qxcbwindow.cpp.html#_ZN10QXcbWindow13setWindowIconERK5QIcon" title="https://code.woboq.org/qt5/qtbase/src/plugins/platforms/xcb/qxcbwindow.cpp.html#_ZN10QXcbWindow13setWindowIconERK5QIcon">https://code.woboq.org/qt5/qtbase/src/plugins/platforms/xcb/qxcbwindow.c...</a>

This method is called indirectly from QWidget::setWindowIcon. I am
pretty sure that it works as you can easily check by xprop any other Qt
window. So the problem must be the icon. If I search for
labplot-worksheet I find only an icon in size 22x22. Looking at the
linked code, I notice that it's not one of the sizes Qt expects and also
none of the sizes KWin expects, see
<a href="https://cgit.kde.org/kwin.git/tree/client.cpp#n1583" title="https://cgit.kde.org/kwin.git/tree/client.cpp#n1583">https://cgit.kde.org/kwin.git/tree/client.cpp#n1583</a>

My suggestion is to try whether any other icon works. And if it does so,
ensure that all relevant icon sizes are available for the
labplot-worksheet.

Cheer
Martin

Am 2019-03-04 17:39, schrieb Alexander Semke:

Re: Aw: Re: setWindowIcon for QDialog

By Friedrich W. H.... at 03/06/2019 - 18:13

Hi,

allow me to chime in with my AFAIK, which though is confirmed by my quick look
at the code:

Am Dienstag, 5. März 2019, 18:21:00 CET schrieb Martin Flöser:
Isn't the more relevant code here the one at the start of that method?

// First read icons from the window itself
const QString themedIconName = iconFromDesktopFile();
if (!themedIconName.isEmpty()) {
setIcon(QIcon::fromTheme(themedIconName));
return;
}

From what I remember, one of the issues with Wayland (and then also with KWin
& its custom X-equivalent "_KDE_NET_WM_DESKTOP_FILE") is that while title
properties for windows are supported, icons are not (something about graphics
resources and different metadata design *insert proper knowledge*). So the
window managers and running-app-instance managers take the icon name only from
the desktop file, no longer enabling to overwrite the icon for certain
windows.
Isn't this the issue still? At least I remember this vaguely from some time
ago.

This quote sadly misses the possibly relevant initial " and I always get the
default application's icon shown."

Cheers
Friedrich

Re: Aw: Re: setWindowIcon for QDialog

By Martin =?ISO-88... at 03/07/2019 - 16:02

Am 2019-03-06 23:13, schrieb Friedrich W. H. Kossebau:
Not in this case as the window is missing the icon property as can be
seen in the xprop output.

But apart from that: yes if the desktop file is specified, the icon is
preferred over the custom icon. But in this specific case it's not the
reason.

Cheers
Martin

Re: Aw: Re: setWindowIcon for QDialog

By Alexander Semke at 03/07/2019 - 17:44

On Donnerstag, 7. März 2019 21:02:49 CET Martin Flöser wrote:
I checked it again with another window manager. Again, it's
<a href="https://cgit.kde.org/labplot.git/tree/src/kdefrontend/datasources/" title="https://cgit.kde.org/labplot.git/tree/src/kdefrontend/datasources/">https://cgit.kde.org/labplot.git/tree/src/kdefrontend/datasources/</a>
DatabaseManagerDialog.cpp#n48

with the icon "network-server-database":

alex@notebook:/usr/share/icons/breeze>find . -name network-server-database*
./places/16/network-server-database.svg
./places/22/network-server-database.svg

xporp for this dialog is:

_NET_WM_ICON_NAME(UTF8_STRING) =
_KDE_NET_WM_DESKTOP_FILE(UTF8_STRING) = "org.kde.labplot2"
_KDE_NET_WM_COLOR_SCHEME(STRING) = "/usr/share/color-schemes/
BreezeHighContrast.colors"
XdndAware(ATOM) = BITMAP
_KDE_NET_WM_USER_CREATION_TIME(CARDINAL) = 28374773
WM_NAME(STRING) = "SQL Database Connections"
_NET_WM_NAME(UTF8_STRING) = "SQL Database Connections — labplot2"
_MOTIF_WM_HINTS(_MOTIF_WM_HINTS) = 0x3, 0x26, 0x1e, 0x0, 0x0
_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_DIALOG,
_NET_WM_WINDOW_TYPE_NORMAL
_XEMBED_INFO(_XEMBED_INFO) = 0x0, 0x1
WM_CLIENT_LEADER(WINDOW): window id # 0x8400008
WM_HINTS(WM_HINTS):
Client accepts input or input focus: True
window id # of group leader: 0x8400008
WM_CLIENT_MACHINE(STRING) = "notebook"
_NET_WM_PID(CARDINAL) = 16708
_NET_WM_SYNC_REQUEST_COUNTER(CARDINAL) = 138412230
WM_CLASS(STRING) = "labplot2", "labplot2"
WM_PROTOCOLS(ATOM): protocols WM_DELETE_WINDOW, WM_TAKE_FOCUS, _NET_WM_PING,
_NET_WM_SYNC_REQUEST, _NET_WM_CONTEXT_HELP
WM_NORMAL_HINTS(WM_SIZE_HINTS):
user specified location: 764, 306
user specified size: 1012 by 726
program specified minimum size: 553 by 596
window gravity: Static

The icon "network-server-database" is not shown in the window title bar.
Killing kwin, starting openbox -> the proper icon is shown. Killing openbox,
starting kwin_x11 -> application's default icon is shown. I don't know how the
window managers are supposed to do the job here, but somehow openbox manages
to show the proper icon despite the empty string
_NET_WM_ICON_NAME(UTF8_STRING)...

Re: Aw: Re: setWindowIcon for QDialog

By Alexander Semke at 04/28/2019 - 04:13

Hi Martin, Hi Friedrich,

any thoughts on the behavior in openbox vs. kwin described below?

Regards,
Alexander

Am Donnerstag, 7. März 2019, 22:44:58 CEST schrieb Alexander Semke:

Re: Aw: Re: setWindowIcon for QDialog

By Alexander Semke at 03/06/2019 - 17:51

HI Martin,

The icon shown in the screenshots I attached (windows vs. kwin) in the
previous email is "document-import-database". I cannot find this icon on my
computer now nor in breeze-icons repository, only "document-import". I'll
check tomorrow what we have in our windows build. Anyway, switching to
"document-import" doesn't help...

I just checked with another icon and dialog:
<a href="https://cgit.kde.org/labplot.git/tree/src/kdefrontend/datasources/" title="https://cgit.kde.org/labplot.git/tree/src/kdefrontend/datasources/">https://cgit.kde.org/labplot.git/tree/src/kdefrontend/datasources/</a>
DatabaseManagerDialog.cpp#n48

Here we use "network-server-database". This icon is available

alex@notebook:/usr/share/icons/breeze>find . -name network-server-database*
./places/16/network-server-database.svg
./places/22/network-server-database.svg

But in the dialog I don't get any icon shown. I'm not sure what a fixed pixel
size means here for svg, though... Any other hints?

Danke und Viele Grüße,
Alexander