You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

GreyGeek

Unregistered

1

Friday, September 30th 2005, 9:56pm

[SOLVED] Qt::Orientation problem

Here is a snippit of the code I am trying to write, which creates a view of a table, displays it, and then prints it. The display works great, the data prints great, but I haven't been able to get the column headers to print yet.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
QSqlQueryModel *BRmodel = new QSqlQueryModel;
BRmodel->setQuery(dbrStr);
if (BRmodel->rowCount() > 0 ){
    QTableView *view = new QTableView;
   view->setModel(BRmodel);
    view->show();
    // add code to create html page from BRmodel row and column data
    QPrinter *printer = new QPrinter;
    QPainter p(printer);
    QFont Courier10("Courier",10);
    p.setFont(Courier10);
    int x_pos = 20;
    int y_pos = 20;
    QHeaderView *viewhhdr = view->horizontalHeader();		
    QString hdrtxt;		
    for (int col = 0; col < viewhhdr->count(); ++col){
	hdrtxt += viewhhdr->model()->headerData(col,Qt::Orientation::Horizontal,Qt::DisplayRole);
....
}


The problem is that it produces an error:

Source code

1
2
3
4
 error C2039: 'Horizontal' : is not a member of 'Qt::Orientation'
...
...
 error C2065: 'Horizontal' : undeclared identifier

but, the API gives:

Source code

1
QAbstractItemModel::headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole )

I have tried just "Qt::Horizontal" and it doesn't work either. I have also tried to recast several times and ways.
What's the magic formula?

This post has been edited 2 times, last edit by "GreyGeek" (Oct 3rd 2005, 4:11pm)


jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

2

Friday, September 30th 2005, 10:03pm

RE: Qt::Orientation problem

Try:

Source code

1
viewhhdr->model()->headerData(col,Qt::Horizontal,Qt::DisplayRole);

GreyGeek

Unregistered

3

Saturday, October 1st 2005, 2:15am

RE: Qt::Orientation problem

Quoted

Originally posted by jacek
Try:

Source code

1
viewhhdr->model()->headerData(col,Qt::Horizontal,Qt::DisplayRole);


Thanks for the reply, but in my last sentence I indicated that I had already tried your solution, "Qt:Horizonal", before I posted.

dimitri

Professional

  • "dimitri" is male

Posts: 1,311

Occupation: Engineer

  • Send private message

4

Saturday, October 1st 2005, 12:55pm

RE: Qt::Orientation problem

Are you using Qt 4? In Qt 4 it's really Qt::Horizontal and it works since it's used in Qt itself.

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

5

Saturday, October 1st 2005, 1:16pm

RE: Qt::Orientation problem

Quoted

Originally posted by GreyGeek
Thanks for the reply, but in my last sentence I indicated that I had already tried your solution, "Qt:Horizonal", before I posted.

Sorry, I haven't noticed it. Could you post the error message you get when you use "Qt::Horizontal"?

GreyGeek

Unregistered

6

Monday, October 3rd 2005, 3:51pm

[SOLVED] Qt::Orientation problem

Taking a weekend break away from a problem can let you take an entirely fresh view of it. When I got to work this morning and saw your request to show the error msg for "Qt::Horizontal" try, as shown in the code snippet below,

Source code

1
2
3
4
5
6
hdrtxt += viewhhdr->model()->headerData(col,Qt::Horizontal,Qt::DisplayRole);

which gives:

haptest.cpp(1266) : error C2679: binary '+=' : no operator found which takes a r
ight-hand operand of type 'QVariant' (or there is no acceptable conversion)

the problem stood out immediately: " 'binary '+=' no operator ...", not the orientation problem I had narrow mindedly focused on last Friday.

I modified the code to:

Source code

1
hdrtxt += viewhhdr->model()->headerData(col,Qt::Horizontal,Qt::DisplayRole).toString();

and it works now.
Thanks jacek!

This post has been edited 1 times, last edit by "GreyGeek" (Oct 3rd 2005, 4:11pm)