PDA

View Full Version : How to resize qtablewidget rows?



robgeek
24th May 2015, 01:48
Good evening!

I have this table(picture 1) and i want to resize the row's height to show the data like the table(picture 2). And set the numbers in the middle, i'm talkin about the height.

I tried:

//Every number i try in place of 2 and 5 changes nothing!
val->setSizeHint(QSize(2, 5));


http://postimg.org/image/igx06smn5/
Sorry don't use attachments, but everytime i try to upload my image i get:

"The following errors occurred:
tables.jpg: This is not a valid image file.

tables.png i get the same message!

anda_skoa
24th May 2015, 11:05
You are not seriously expecting an helpful answer, right?

Trying to increase your post count?

Cheers,
_

robgeek
24th May 2015, 15:36
Sorry!

What did i do? I'm asking questions like i always do. Only thing different is the link, but i said i didn't use attachments because i'm having problems with it. If i did something wrong, i believe is more useful tell me what i did and i don't do anymore instead this answer.

I just want to set the height of the lines in my qtablewidget a little smaller, but "sizeHint" is not working!

anda_skoa
24th May 2015, 16:20
What did i do?

You neglected to provide any useful information.

According to you you have an object "val" of an unknow type, which apparently has a setSizeHint() method that takes a QSize object.

Maybe setSizeHint() of that unknown type just stores the data, maybe it even ignores it.
Since the type is unknown to anyone but yourself, noone can possibly give any helpful advice.

Cheers,
_

robgeek
24th May 2015, 16:40
Ok, now i see. Really sorry about that!

The object "val" is a QTableWidgetItem.

Bellow, the method:

void showHistTable(QTableWidget *table, Data historic) {
for(int i = 0; i < historic.size; i++) {
table->insertRow( i );
for(int j = 0; j < historic.limit; j++) {
QTableWidgetItem *val;

// Put zero in front of the number if he is smaller than 10.
if(historic.historic[i][j] < 10)
val = new QTableWidgetItem( QString("0").append( QString::number( historic.historic[i][j] ) ) );
else
val = new QTableWidgetItem( QString::number( historic.historic[i][j] ) );

val->setTextAlignment( Qt::AlignHCenter );
val->setSizeHint(QSize(2, 5));// Nothing is changed if i set different vals for the arguments.

// Set the row colors
if(((i + 1) % 2) == 0)
val->setBackgroundColor( QColor(149, 149, 149, 255) );
else
val->setBackgroundColor( QColor(186, 186, 186, 255) );

table->setItem(i, j, val);
}
}
}

robgeek
25th May 2015, 02:07
I don't know if the numbers i'm using are too small(pixels), i tried bigger but nothing changed too.

wysota
25th May 2015, 07:01
If I remember correctly setSizeHint() of a QTableWidget item is ignored by default so it doesn't really matter what you set there.

By the way, 2 and 5 are really weird values to set a an item size. What would you expect to fit in that?

robgeek
25th May 2015, 15:59
By the way, 2 and 5 are really weird values to set a an item size. What would you expect to fit in that?
Nothing, i just wanted to see clearly if sizeHint was working.


If I remember correctly setSizeHint() of a QTableWidget item is ignored by default so it doesn't really matter what you set there.
So, is there another way to do what i want? How?

wysota
25th May 2015, 18:45
Use a custom delegate with reimplemented sizeHint.