[SOLVED] QTableWidgetItem no data only check flag



  • I've got some QTableWidget, and initializing items like this:
    @QTableWidgetItem * item = table->item(i,j);

    if(item == NULL)
    {
    item = new QTableWidgetItem();
    item->setFlags(Qt::NoItemFlags);
    m_ui->tableWidget->setItem(i,j,item);
    }

    if(m_ec.matrix[headerId_i][headerId_j]) // value
    item->setData(Qt::CheckStateRole, Qt::Checked);
    else
    item->setData(Qt::CheckStateRole, Qt::Unchecked);

    if(m_rn.matrix[headerId_i][headerId_j]))// readonly
    item->setFlags(Qt::NoItemFlags);
    else
    item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsUserCheckable);@
    I mean I need checkable items in table with maybe some UserRole data and toolTips but w/o Display data. I get this but I still have some space in cells of my table. The question is how to remove or maybe hide these empties ?



  • Or maybe anyone know how to set chekbox in center of cell ?



  • You can only put the checkbox in the center of a cell, if you create your own delegate. That is not worth it, I think.

    Couldn't you just make the column with your checkboxes narrow enough so it basically only shows your check box?



  • Thanks. I think it's really don't worth it to make a delegate. I asked because I don't know simple method but maybe someone knows. I resize my column close enough but some header text is bigger then 3 symbols long, so there is no way to do SIMPLE nice look, without using delegate.



  • You could considder, if you have space to fill, to just put a textual representation of the value next to the check box. Depending on the meaning, that could be yes/no, true/false, on/off, or something short and simple like that.



  • I found solution I made my horizontal headers only digits in data role, and all text in tool tip role, but vertical header leave with text(because it's actually duplicates horizontal header) . So now it has a nice look. Andre, thanks for the help.


Log in to reply
 

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