Results 1 to 9 of 9

Thread: How to resize qtablewidget rows?

  1. #1
    Join Date
    Mar 2015
    Posts
    105
    Thanks
    50

    Default How to resize qtablewidget rows?

    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:
    Qt Code:
    1. //Every number i try in place of 2 and 5 changes nothing!
    2. val->setSizeHint(QSize(2, 5));
    To copy to clipboard, switch view to plain text mode 


    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to resize qtablewidget rows?

    You are not seriously expecting an helpful answer, right?

    Trying to increase your post count?

    Cheers,
    _

  3. #3
    Join Date
    Mar 2015
    Posts
    105
    Thanks
    50

    Default Re: How to resize qtablewidget rows?

    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!

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to resize qtablewidget rows?

    Quote Originally Posted by robgeek View Post
    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,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    robgeek (24th May 2015)

  6. #5
    Join Date
    Mar 2015
    Posts
    105
    Thanks
    50

    Default Re: How to resize qtablewidget rows?

    Ok, now i see. Really sorry about that!

    The object "val" is a QTableWidgetItem.

    Bellow, the method:
    Qt Code:
    1. void showHistTable(QTableWidget *table, Data historic) {
    2. for(int i = 0; i < historic.size; i++) {
    3. table->insertRow( i );
    4. for(int j = 0; j < historic.limit; j++) {
    5.  
    6. // Put zero in front of the number if he is smaller than 10.
    7. if(historic.historic[i][j] < 10)
    8. val = new QTableWidgetItem( QString("0").append( QString::number( historic.historic[i][j] ) ) );
    9. else
    10. val = new QTableWidgetItem( QString::number( historic.historic[i][j] ) );
    11.  
    12. val->setTextAlignment( Qt::AlignHCenter );
    13. val->setSizeHint(QSize(2, 5));// Nothing is changed if i set different vals for the arguments.
    14.  
    15. // Set the row colors
    16. if(((i + 1) % 2) == 0)
    17. val->setBackgroundColor( QColor(149, 149, 149, 255) );
    18. else
    19. val->setBackgroundColor( QColor(186, 186, 186, 255) );
    20.  
    21. table->setItem(i, j, val);
    22. }
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by robgeek; 24th May 2015 at 16:44.

  7. #6
    Join Date
    Mar 2015
    Posts
    105
    Thanks
    50

    Default Re: How to resize qtablewidget rows?

    I don't know if the numbers i'm using are too small(pixels), i tried bigger but nothing changed too.

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to resize qtablewidget rows?

    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #8
    Join Date
    Mar 2015
    Posts
    105
    Thanks
    50

    Default Re: How to resize qtablewidget rows?

    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?

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to resize qtablewidget rows?

    Use a custom delegate with reimplemented sizeHint.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 13
    Last Post: 3rd January 2015, 20:41
  2. Deselecting Rows in a QTableWidget
    By Sarol in forum Newbie
    Replies: 1
    Last Post: 26th July 2011, 23:47
  3. QTableWidget set value of many rows in One Step
    By sagirahmed in forum Newbie
    Replies: 3
    Last Post: 11th October 2010, 06:08
  4. How to set rows of QtableWidget to the same height?
    By sawerset in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2008, 18:09
  5. Resize rows and cols in a Tablewidget
    By zorro68 in forum Qt Programming
    Replies: 2
    Last Post: 11th February 2007, 12:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.