Results 1 to 7 of 7

Thread: Get QTableWidget Cell width and height

  1. #1
    Join Date
    Jul 2015
    Location
    Austria
    Posts
    20
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Question Get QTableWidget Cell width and height

    Hi everyone,

    I want to resize a QLabel(in the labels are images) to fit in a cell. I use
    Qt Code:
    1. label->setFixedSize(ui->tableWidget->columnWidth(currentColumn),ui->tableWidget->rowHeight(currentRow));
    To copy to clipboard, switch view to plain text mode 
    to set the labels size and than
    Qt Code:
    1. QPixmap p=QPixmap(iterator->next());
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. label->setPixmap(p.scaled(label->width(),label->height(),Qt::KeepAspectRatio));
    To copy to clipboard, switch view to plain text mode 
    to keep the image aspect ratio. I get the currentColumn/Row from a selectionmodel.

    When the cell doesn´t have row/colspan all works fine. But when i span (for example 2 rows) then i only get the height of the first row and i want to get the height of r1+r2. So the Image only fit the size of the first cell before the span and ignores the additional size from the span.


    I didn´t find something about cellwidth/cellheight so I´m asking here now.


    (And sorry for my bad english)

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Get QTableWidget Cell width and height

    Probably need to call the base class QTableWidget::rowSpan() and/or QTableWidget::columnSpan() methods and then query for the heights / widths of the additional rows if either method returns > 1.

  3. #3
    Join Date
    Jul 2015
    Location
    Austria
    Posts
    20
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Get QTableWidget Cell width and height

    I can't find these methods...

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Get QTableWidget Cell width and height

    Sorry, I miss-typed. I meant QTableView. Always look in the base classes for functionality that is "missing" from the class you are instantiating.

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

    mayrhofer (27th December 2015)

  6. #5
    Join Date
    Jul 2015
    Location
    Austria
    Posts
    20
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Get QTableWidget Cell width and height

    Ok i'll try and reply after

  7. #6
    Join Date
    Jul 2015
    Location
    Austria
    Posts
    20
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Get QTableWidget Cell width and height

    can you post an example of how to use this? i don´t know how to get to the parent´s method.

  8. #7
    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: Get QTableWidget Cell width and height

    You just call them like any other method.
    A QTableWidget is a QTableView.

    Cheers,
    _

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

    mayrhofer (27th December 2015)

Similar Threads

  1. Replies: 2
    Last Post: 19th July 2013, 09:34
  2. Pusbutton height and width
    By seany in forum Qt Programming
    Replies: 6
    Last Post: 7th June 2013, 06:35
  3. Replies: 3
    Last Post: 9th November 2012, 18:55
  4. Replies: 1
    Last Post: 25th May 2010, 14:44
  5. Replies: 1
    Last Post: 7th December 2009, 18:56

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.