Loading icon for toolbar from file

33 views
Skip to first unread message

luafox

unread,
Jun 24, 2012, 10:50:53 AM6/24/12
to lqt-bindings
Hello,

I have a very simple question which bugs me a lot. I would like to add
a
number of icons to QToolBar but I have problems getting them to
display.

I tried the following code:

require'qtcore'
require'qtgui'

[...]

local testicon = QPixmap("C:\Program
Files\Lua\lqt\test\Theme\default\test.bmp")
--testicon = QIcon(testicon)
local test2 = QIcon("C:\Program Files\Lua\lqt\test\Theme\default
\test.png")

local toolbar = QToolBar()
toolbar:addAction("Hello")
toolbar:addAction(testicon,"Test")
toolbar:addAction(test2,"Test2")

[...]

But the icon is not displayed. The first text button ("Hello")
displays fine,
the second one (testicon) displays as a square icon but is completely
empty
and the third one (test2) looks like the first one with different
text. Can
you give me a short hint on how to load the icon correctly?

Thank you very much!
Michael

Michal Kottman

unread,
Jun 24, 2012, 11:20:58 AM6/24/12
to lqt-bi...@googlegroups.com


Dňa 24.6.2012 16:50, "luafox" <in...@luafox.com> napísal(-a):


>
> Hello,
>
> I have a very simple question which bugs me a lot. I would like to add
> a
> number of icons to QToolBar but I have problems getting them to
> display.
>
> I tried the following code:
>
> require'qtcore'
> require'qtgui'
>
> [...]
>
> local testicon = QPixmap("C:\Program
> Files\Lua\lqt\test\Theme\default\test.bmp")
> --testicon = QIcon(testicon)
> local test2 = QIcon("C:\Program Files\Lua\lqt\test\Theme\default
> \test.png")

The problem may be in the paths in the string literals. Lua treats backslash in strings as an escape character (as in C). Therefore "\test" is treated as a tab character followed by "est". Either double all backslashes "\\" or switch to forward slash "/" (it works also in Windows).

luafox

unread,
Jun 26, 2012, 12:57:39 AM6/26/12
to lqt-bi...@googlegroups.com


Am Sonntag, 24. Juni 2012 17:20:58 UTC+2 schrieb Michal Kottman:

The problem may be in the paths in the string literals. Lua treats backslash in strings as an escape character (as in C). Therefore "\test" is treated as a tab character followed by "est". Either double all backslashes "\\" or switch to forward slash "/" (it works also in Windows).


Thanks. I think I was to focused on the question whether to use QIcon or
QPixmap and whether you need to do something magic to convert the file format
that I did not see this.

Thanks, it works now!
Michael

Michael Gerbracht

unread,
Jun 23, 2012, 11:23:08 AM6/23/12
to lqt-bi...@googlegroups.com
Hello,

I have a very simple question which bugs me a lot. I would like to add a
number of icons to QToolBar but I have problems getting them to display.

I tried the following code:

require'qtcore'
require'qtgui'

[...]

local testicon = QPixmap("C:\Program
Files\Lua\lqt\test\Theme\default\test.bmp")
--testicon = QIcon(testicon)
local test2 = QIcon("C:\Program Files\Lua\lqt\test\Theme\default\test.png")

Michael Gerbracht

unread,
Jun 24, 2012, 11:30:42 AM6/24/12
to lqt-bi...@googlegroups.com
In article
<CAPtieMyrrR3fhYCADkGMxEe+...@mail.gmail.com>, Michal
Kottman <k0mp...@gmail.com> wrote:
> Dòa 24.6.2012 16:50, "luafox" <in...@luafox.com> napísal(-a):

> > local testicon = QPixmap("C:\Program
> > Files\Lua\lqt\test\Theme\default\test.bmp") --testicon = QIcon(testicon)
> > local test2 = QIcon("C:\Program Files\Lua\lqt\test\Theme\default
> > \test.png")
> The problem may be in the paths in the string literals. Lua treats
> backslash in strings as an escape character (as in C). Therefore "\test" is
> treated as a tab character followed by "est". Either double all backslashes
> "\\" or switch to forward slash "/" (it works also in Windows).

Reply all
Reply to author
Forward
0 new messages