Results 1 to 3 of 3

Thread: size of QTableWidgetItem will not change

  1. #1
    Join Date
    May 2012
    Posts
    1
    Qt products
    Qt4

    Default size of QTableWidgetItem will not change

    Hi
    I have a problem with changing the width of QTableWidgetItems.
    here's a picture of the problem:
    comboboxes.png
    there are 3 columns. The blue lines mark the width of the items in question.
    The width will not change after calling QTableView::setColumnWidth() or giving the item a sizeHint, or resizing the QComboBox itself before or after any of these calls.
    setDefaultSectionSize() works, but is unsuitable because the first column has to be wider than the other two.
    Setting the width of the first column doesn't work either, and I don't know the width of the text in pixels so I can remove the empty space marked by the red line.
    So it won't work with or without a cell widget.
    What I need is something like this:
    comboboxes2.png

    Here's the code I currently use to create a row in the table:
    Qt Code:
    1. if(this->QTableWidget::columnCount() != 3) {
    2. this->table_widget::set_column_count(3, false); //calls setColumnCount
    3. this->setColumnWidth(0, 200); //does not work
    4. this->setColumnWidth(1, 40); //neither does this
    5. this->setColumnWidth(2, 40); //...
    6. }
    7. this->QTableWidget::insertRow(this->cur_index); //cur_index = current row
    8. this->QTableWidget::setItem(this->cur_index, 0, new dfts::var_table_item(*var, flags));
    9. this->QTableWidget::setItem(this->cur_index, 1, new dfts::var_table_item);
    10. this->QTableWidget::setItem(this->cur_index, 2, new dfts::var_table_item);
    11. this->set_cell_widget(this->cur_index, 1, create_default_color_combobox(QSize(40, 0))); //create a combobox size 40:constructor-default
    12. this->set_cell_widget(this->cur_index, 2, create_default_color_combobox(QSize(40, 0)));
    To copy to clipboard, switch view to plain text mode 
    horizontal and vertical headers are set invisible, in case that matters.

    So my question is: why can't I control the width of these columns?
    Attached Images Attached Images

  2. #2
    Join Date
    Mar 2012
    Location
    White Sands Missile Range, NM
    Posts
    1
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: size of QTableWidgetItem will not change

    Are you missing the table_widget reference in

    this->setColumnWidth(0,200)

  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: size of QTableWidgetItem will not change

    Some of the oddest coding I have seen for a while.

    Anyway, try:
    Qt Code:
    1. horizontalHeader()->resizeSection(0, 200);
    2. horizontalHeader()->resizeSection(1, 20);
    3. horizontalHeader()->resizeSection(1, 20);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Font size of lcdnumber does not change
    By Niamita in forum Qt Programming
    Replies: 0
    Last Post: 27th January 2012, 07:55
  2. Change text color in QTableWidgetItem
    By npascual in forum Qt Programming
    Replies: 0
    Last Post: 10th May 2011, 17:03
  3. How do you change the size of a QMenubar
    By JonR79 in forum Qt Programming
    Replies: 1
    Last Post: 21st November 2008, 23:15
  4. change picture size
    By raphaelf in forum Newbie
    Replies: 1
    Last Post: 27th November 2006, 18:15
  5. change font size and button size of QMessageBox
    By nass in forum Qt Programming
    Replies: 6
    Last Post: 13th September 2006, 19:16

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.