+ Reply to Thread
Results 1 to 5 of 5

Thread: Different widths for each column in different row in QTableWidget - Qt5

  1. #1
    Join Date
    Mar 2017
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Different widths for each column in different row in QTableWidget - Qt5

    Hi,

    I am creating a QTableWidget with multiple rows and columns.
    And inserting custom QWidgets into the table.
    These custom widgets are having diff. widths.

    I am giving the below settings for the QTableWidget:

    QTableWidget *m_pTimelineTable = new QTableWidget();

    m_pTimelineTable->setRowCount(m_masterLayout.sRowCount);
    m_pTimelineTable->setColumnCount(m_masterLayout.sColCount);

    m_pTimelineTable->horizontalHeader()->hide();
    m_pTimelineTable->verticalHeader()->hide();

    m_pTimelineTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContent s);
    m_pTimelineTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContent s);

    m_pTimelineTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysO ff);
    m_pTimelineTable->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff );
    ...
    ...
    //Custom Widget
    MyView *mView = new MyView(); //Inherited from QWidget
    int iCustomWidth = 600;
    mView->setGeometry(0,0,iCustomWidth,250);

    //This iCustomWidth will be different for each custom widget
    ...
    ...
    m_pTimelineTable->setCellWidget((*bIterator).row_num, (*bIterator).col_num, mView);[/I][/I]


    Now, all CustomWidgets in each cell of the QTableWidget is having the same width.

    Anyone, could you please suggest me to get the diff. widths of custom widgets in each cell ...

    Thanks
    Kalyan

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,874
    Thanks
    3
    Thanked 449 Times in 432 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Different widths for each column in different row in QTableWidget - Qt5

    Do you want to set the cell width or widget width?

    or

    Do you want to set the cell width and fit the widget to the cell width ?


    All cells in a column will have same width, you can try setting column span for the cell.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Mar 2017
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Different widths for each column in different row in QTableWidget - Qt5

    Quote Originally Posted by Santosh Reddy View Post
    Do you want to set the cell width or widget width?

    or

    Do you want to set the cell width and fit the widget to the cell width ?


    All cells in a column will have same width, you can try setting column span for the cell.
    Yes...exactly...I am looking for "set the cell width and fit the widget to the cell width".

    If not with QTableWidget, is there any other widget/layout to achieve this ?

    Thanks

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,874
    Thanks
    3
    Thanked 449 Times in 432 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Different widths for each column in different row in QTableWidget - Qt5

    For different width cells you will have to use column span.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    Mar 2017
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Different widths for each column in different row in QTableWidget - Qt5

    Thank You Santosh.

+ Reply to Thread

Similar Threads

  1. Replies: 2
    Last Post: 19th January 2016, 05:47
  2. [Solved] Synchronizing column widths between QTableViews
    By Phlucious in forum Qt Programming
    Replies: 0
    Last Post: 7th March 2013, 00:17
  3. Saving QTableView Column Widths
    By stefanadelbert in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2010, 16:23
  4. Dynamic Sizing of QTableView Column Widths
    By tntcoda in forum Qt Programming
    Replies: 1
    Last Post: 17th June 2009, 18:30
  5. auto resizing column/row widths
    By raman_31181 in forum Qt Programming
    Replies: 2
    Last Post: 11th September 2008, 18: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