QListWidgetItem:setTextAlignment

397 views
Skip to first unread message

Ralf Van Bogaert

unread,
Oct 3, 2011, 7:06:17 AM10/3/11
to lqt-bi...@googlegroups.com
Hi,

Simple question. I'd like to adjust the text alignment of a QListWidgetItem both horizontally and vertically.
In cpp, it's done like this (for example)

QListWidgetItem::setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter)

However, in Lua, the pipe character '|' is not valid, and I'm not sure how to implement this.
Maybe through a QFlag?

Regards

Ralf

Michal Kottman

unread,
Oct 3, 2011, 9:09:47 AM10/3/11
to lqt-bi...@googlegroups.com
On Mon, 2011-10-03 at 13:06 +0200, Ralf Van Bogaert wrote:
> Hi,
>
> Simple question. I'd like to adjust the text alignment of a
> QListWidgetItem both horizontally and vertically.
> In cpp, it's done like this (for example)
>
> QListWidgetItem::setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter)
>
> However, in Lua, the pipe character '|' is not valid, and I'm not sure
> how to implement this.

In case of flags (i.e. integers with different bits set), the "or" = "|"
operator is equivalent to addition. Therefore the following will work:

item:setTextAlignment(Qt.AlignmentFlag.AlignHCenter +
Qt.AlignmentFlag.AlignVCenter)

The reason Lqt didn't generate a "nice" wrapper in form of:

item:setTextAlignment {'AlignHCenter', 'AlignVCenter'}

is because of the definition of QListWidgetItem::setTextAlignment in Qt,
which uses a parameter "int alignment" instead of "Qt::Alignment
alignment". Blame the authors of Qt :)


Ralf Van Bogaert

unread,
Oct 3, 2011, 9:33:54 AM10/3/11
to lqt-bi...@googlegroups.com
Not blaming anyone :) but the solution doesn't seem to work, the second argument is ignored?

Regards

Ralf

Michal Kottman

unread,
Oct 3, 2011, 5:24:50 PM10/3/11
to lqt-bi...@googlegroups.com
On 3 October 2011 15:33, Ralf Van Bogaert <poos...@gmail.com> wrote:
> On Mon, Oct 3, 2011 at 3:09 PM, Michal Kottman <k0mp...@gmail.com> wrote:
>>
>> On Mon, 2011-10-03 at 13:06 +0200, Ralf Van Bogaert wrote:
>> > Hi,
>> >
>> > Simple question. I'd like to adjust the text alignment of a
>> > QListWidgetItem both horizontally and vertically.
>> > In cpp, it's done like this (for example)
>> >
>> > QListWidgetItem::setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter)
>> >
>> > However, in Lua, the pipe character '|' is not valid, and I'm not sure
>> > how to implement this.
>>
>> In case of flags (i.e. integers with different bits set), the "or" = "|"
>> operator is equivalent to addition. Therefore the following will work:
>>
>> item:setTextAlignment(Qt.AlignmentFlag.AlignHCenter +
>> Qt.AlignmentFlag.AlignVCenter)
>>
>
> Not blaming anyone :) but the solution doesn't seem to work, the second
> argument is ignored?

There is no second argument, only addition. Think of it this way:

local desiredFlag = Qt.AlignmentFlag.AlignHCenter +
Qt.AlignmentFlag.AlignVCenter
item:setTextAlignment(desiredFlag)

Reply all
Reply to author
Forward
0 new messages