[Qt-interest] Text alignment

Paul Colby qt at colby.id.au
Wed Nov 4 09:17:39 CET 2009


I just wrote a very simple test app... works as expected...

#include <QApplication>
#include <QTableWidget>
#include <QTableWidgetItem>

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    QTableWidget *tableWidget=new QTableWidget(10,10);
    QTableWidgetItem *item = new QTableWidgetItem(QString::fromAscii("abc"));
    item->setTextAlignment(Qt::AlignHCenter);
    tableWidget->setItem(0,0,item);
    tableWidget->show();
    return app.exec();
}

Simply puts "abc" into the first cell, and centers it (horiztonally).

If that doesn't reveal to you what your doing wrong, then send us more
info... ie include full (or at least more) source code.  For example,
what is the "tableItem" property that your code is referring to?

pc.

On Wed, Nov 4, 2009 at 5:03 PM, Phil <phillor at telstra.com> wrote:
> On Tue, 3 Nov 2009 07:47:44 pm Paul Colby wrote:
>> The problem, essentially, is that the way you are adding new items
>> from the list *replaces* the original items, but you are only setting
>
> Thanks Paul. I tried both of your suggestions but, unfortunately, the
> alignment is still left justified. Take the following code for example:
>
> for(int column = 0; column < 4; column++)
>  {
>    tableItem[row][column] = new QTableWidgetItem("x");
>    tableItem[row][column]->setTextAlignment(Qt::AlignHCenter);
>  }
>
> Shouldn't the x be aligned in the centre of each cell rather on the left side?
>
> It's not unlikely that this problem relates to a dialog problem that I will
> post as a separate question.
>
> --
> Regards,
> Phil
>
>
>



-- 
http://colby.id.au




More information about the Qt-interest-old mailing list