[Solved] QTableWidget columns with different width



  • Hello there,
    Anyone has some piece of code to understand how to define a QTableWidget object where every column has a different width?
    I tried resizeColumnToContents( int ) and setColumnWidth ( int, int ) with no luck :(

    Thanks!



  • But, that is basically wat you need to do to get different column widths. Could you show the relevant code with your attempt please?



  • Hi! In my case, every column will contain data with a very specific size. Any clue?
    This is my code, but is not working at all:

    @
    StepsViewer::StepsViewer(QWidget *parent) : QTableWidget(parent)
    {
    setColumnCount(3);
    setColumnWidth(0, 80);
    setColumnWidth(1, 40);
    setColumnWidth(2, 20);
    setHorizontalHeaderLabels(QStringList() << tr("Interval") << tr("Frames") << tr("Add"));
    ...
    }@

    Edit (Andre): fixed code formatting. Please do that yourself next time...



  • OK, so you are inheriting QTableWidget.
    Could you try what happens if you set the column widths after you set the data? At first sight, the above should work, but I believe you if you say it doesnt.



  • I found the problem! All my fault :S
    In some place from another class I was doing this:
    @
    k->stepViewer = new StepsViewer;
    k->stepViewer->verticalHeader()->hide();
    k->stepViewer->horizontalHeader()->setResizeMode(QHeaderView::Stretch); // <- Aaaargh! :S
    @

    Shame on me! setColumnWidth(int, int) really works!
    My apologies :(


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.