Custom QTableView



  • Hi!
    Are there any ways to get such a QTableView? I need independent sub-tables ("independent" in sense of separate indexing and adding new rows from separate models), but these sub-tables must share common columns
    QTableViews


  • Lifetime Qt Champion

    Hi,

    Do you mean you would have something like 3 different QTableView glued to each other in order to show the information you want ?





  • @SGaist
    Yes, something like that. These QTableViews must have the same columns but the horizontal rows (without cells) with titles are mandatory. And it could be a totally different number of rows in the each 'glued' QTableViews. I can't even imagine how to implement it.



    • create the 3 table models
    • create 2 table models with the same number of columns but just 1 row, fill element 0,0 of these models with the title
    • use KConcatenateRowsProxyModel and add the 5 models in the order they should appear
    • use QTableView::setSpan to make the the headers span multiple columns

    Alternatively:

    • create 3 QTableView, one for each model
    • set their size policy as QSizePolicy::Minimum and disable the scrollbars
    • lay them out in QWidget with a QVBoxLayout with no margins or borders
    • add the widget to a QScrollArea


  • @VRonin
    Maybe :) but i don't know how to insert sub-titles to its places like in the picture above. This complex table is a reflection of badly structured paper utility bill and the customer wants total correspondence. :(



  • @Tikani said in Custom QTableView:

    how to insert sub-titles

    QAbstractItemModel* model = new QStandardItemModel(this);
    model->insertCoulmns(0,4);
    model->insertRows(0,5);
    model->setData(model->index(0,0),QStringLiteral("Subtitle"));
    for(int j=1;j<5;++j){
    for(int i=0;i<4;++i){
    model->setData(model->index(j,i),QString::number(j) + ','+QString::number(i)); 
    }}
    QTableView* view=new QTableView(this);
    view->setModel(model);
    view->setSpan(0,0,1,4);
    view->horizontalHeader()->hide();
    view->verticalHeader()->hide();
    

Log in to reply
 

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