Results 1 to 4 of 4

Thread: get QTableWidget Horizontal Label Text?

  1. #1
    Join Date
    Jun 2015
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default get QTableWidget Horizontal Label Text?

    hey guys (again )
    now, im just trying to access the text of a horizontal header, of my current Cell, to display it in a label, but i dont really get to know how to do this..
    i tried this:
    Qt Code:
    1. int buf;
    2. buf = table->currentColumn();
    3. actualCol->setText(QString::number(table->horizontalHeaderItem(buf);
    To copy to clipboard, switch view to plain text mode 
    can someone help me?


    EDIT: Got it!
    Qt Code:
    1. QString buf;
    2. buf = table->horizontalHeaderItem(table->currentItem()->column())->text(); // get the current items header
    3. actualCol->setText(buf);
    To copy to clipboard, switch view to plain text mode 
    Last edited by schinkengott; 15th June 2015 at 18:00.

  2. #2
    Join Date
    Jun 2015
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: get QTableWidget Horizontal Label Text?

    ok, i need your help again. i want to print out my whole qtable, with headers.
    but im only able to print out the rows/cols without header, using a QTextDocument.
    how can i put the headers in?
    Qt Code:
    1. for(int row=0;row<getMaxRow();row++)
    2. {
    3. for(int col=0;col<getMaxCol();col++)
    4. {
    5. //QTextTableCell hHeader = docTable->cellAt(0,col);
    6. //hHeader.setFormat(cellFormat);
    7. //hHeader.firstCursorPosition().insertText(table->horizontalHeaderItem(table->columnAt(col))->text());
    8. QTextTableCell cell = docTable->cellAt(row+1,col+1);
    9. cell.setFormat(cellFormat);
    10. cell.firstCursorPosition().insertText(table->item(row+1,col+1)->text());
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    this doesnt work

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: get QTableWidget Horizontal Label Text?

    It may help if you shared what "doesn't work" about it?

  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 Horizontal Label Text?

    how can i put the headers in?
    First question is, why are you using row+1 and col+1? Tables start at row = 0 and col = 0, so as soon as your row or col variables reach their maximum values, you'll be trying to access table items that don't exist because they are beyond the range of getMaxRow() or getMaxCol().

    Second, if what you mean by "Horizontal Label Text" are the column headers, then you simply retrieve the QTableItem from the table using QTableWidget::horizontalHeaderItem() for each column in a loop over all the columns, and add that to your QTextDocument before retrieving the contents of the table's cells.

Similar Threads

  1. no horizontal scroll bar in QTableWidget
    By moskk in forum Newbie
    Replies: 11
    Last Post: 13th April 2017, 21:22
  2. Vertical label on table horizontal header
    By ipkiss in forum Qt Programming
    Replies: 1
    Last Post: 11th February 2014, 19:03
  3. How to edit Horizontal Header Item in QTableWidget
    By ioannis in forum Qt Programming
    Replies: 6
    Last Post: 5th March 2013, 18:50
  4. [SOLVED] QTableWidget subclass and horizontal header
    By nephre in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2010, 22:41
  5. Setting two horizontal header labels for QTablewidget
    By arunvv in forum Qt Programming
    Replies: 2
    Last Post: 20th August 2009, 17:58

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.