[Qt-interest] qtableview : is it possible to add an extra"filter row" above the header ?

Frank Tiekink (IDE) f.p.tiekink at ide.nl
Tue Dec 2 09:11:55 CET 2008


Hi Anthony,

Take a look at QIcsTable from ICS (www.ics.com). They support multiple rows in headers. It's a commercial package, but it may be worthwhile considering the time you may need to spend to get things up and running.

Frank Tiekink

-----Oorspronkelijk bericht-----
Van: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] Namens Anthony Serdyukov
Verzonden: dinsdag 2 december 2008 5:57
Aan: david.jobet at free.fr
CC: qt-interest at trolltech.com
Onderwerp: Re: [Qt-interest] qtableview : is it possible to add an extra"filter row" above the header ?

Looks like a thorny path. Anyway, you just have to try something, your
task is not so simple to solve it theoretically. Unlikely somebody can
give you a ready solution.
Good luck, David.

2008/12/2  <david.jobet at free.fr>:
> Mmmm....
>
> Another option perhaps :
> - wrap the QTableView in another QAbstractScrollArea
> - hide the tableview's scrollbars
> - reserve some space to display the row filter widget
> - connect the container abstractscrollarea's scrollbars on the tableview's one
> - add the glue to handle the scrolling of the tableview in the abstractscrollarea (nether done that before)
> - add the glue to synchronize the headerview's layout change with the filter row layout
>
> Never done that kind of stuff before.
> Do you think it's doable or should I give up straight away ? :-)
>
> Tx
>
> David
>
> skeleton example :
> class MyWrapper : public QAbstractScrollArea
> {
>  MyWrapper(QTableView *view, QWidget *parent)
>  : QAbstractScrollArea(parent)
>  , wrappedView_(view)
>  {
>    QVBoxLayout *vLayout = new QVBoxLayout(this);
>    filterRowLayout_ = new QHBoxLayout(vLayout);
>    populateFilterRowWidgets_(filterRowLayout_);
>    vLayout->addWidget(wrappedView_);
>
>    wrappedView_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
>    wrappedView_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
>    wrappedView_->setFrameStyle(NoFrame);
>
>    connect(verticalScrollBar(), SIGNAL(valueChanged(int), wrappedView_->verticalScrollBar(), SLOT(setValue(int)));
>    connect(horizontalScrollBar(), SIGNAL(valueChanged(int), wrappedView_->horizontalScrollBar(), SLOT(setValue(int)));
>
>    setViewPortMargins(0, filterRowLayout_->height(), 0, 0);
>  }
>
>  // implements QAbstractScrollArea stuff to handle QTableView here
>  // implements stuff to synchronize headerview and filterRowLayout's synch
>
> private :
>  QTableView  *wrappedView_;
>  QHBoxLayout *filterRowLayout_;
> };
>
> ----- Mail d'origine -----
> De: Anthony Serdyukov <uksus70 at gmail.com>
> À: david jobet <david.jobet at free.fr>
> Cc: qt-interest at trolltech.com
> Envoyé: Mon, 1 Dec 2008 05:29:54 +0100 (CET)
> Objet: Re: [Qt-interest] qtableview : is it possible to add an extra "filter row" above the header ?
>
> If you subclass QHeaderView, the only interesting method to
> reimplement is paintSection. Оf course you can render widget there,
> but this will be just an image of a widget, without user input.
>
> 2008/12/1  <david.jobet at free.fr>:
>> I was thinking, maybe it's possible to subclass qheaderview instead, then replace the horizontal header of the table by my own.
>> That way, it would :
>> - be in the scroll area
>> - QTableView::updateGeometries() would handle reserving enough space with setViewportMargins() for me
>> - I could then add my widgets and a headerview in a vertical layout in my reimplementation
>>
>> Does it sound doable ?
>>
>> Tx
>>
>> David
>>
>> ----- Mail d'origine -----
>> De: Anthony Serdyukov <uksus70 at gmail.com>
>> À: qt-interest at trolltech.com
>> Envoyé: Mon, 1 Dec 2008 04:34:49 +0100 (CET)
>> Objet: Re: [Qt-interest] qtableview : is it possible to add an extra "filter row" above the header ?
>>
>> I'd subclass QTableView. I think this is the way you should choose.
>>
>> 2008/11/30  <david.jobet at free.fr>:
>>> OK, I did understand well in that case.
>>> This is NOT something I want to do : I don't want those controls to be part of the table. (orthogonal stuff => must be separate)
>>>
>>> I just want them to be aligned with the table so that the user understand its use.
>>>
>>> It leaves me with only 1 choice if QT doesn't have an API :
>>> - implement a custom layout able to synchronize with header move/resize signals
>>>
>>> David
>>>
>>> ----- Mail d'origine -----
>>> De: Tiago Correia <tiago at cnotinfor.pt>
>>> À: qt-interest at trolltech.com
>>> Envoyé: Sun, 30 Nov 2008 06:09:17 +0100 (CET)
>>> Objet: Re: qtableview : is it possible to add an extra "filter row" above the header ?
>>>
>>> Hi,
>>> Delegates are only for dealing with the interaction between the user and the
>>> GUI. They allow you to add custom widgets (comboboxes, ...) on a cell. Check
>>> the classe QAbstractItemDelegate.
>>>
>>> This should be an easy way to create custom widgets for row 0. Just for
>>> methods you reimplement (editorEvent, paint, setEditor, setModaldata,
>>> createEditor), you must just do something if the row is equal 0, and do
>>> different things for each column.
>>>
>>> Then I said something wrong. You should create a class from
>>> QAbstractProxyModel, that would move your data a row below. Just reimplement
>>> the virtual fucntions and use the sibling methods from the QModelItem to get
>>> the item in row above (since row 1, should be the data form row 0)
>>>
>>> The only think that I think it is going to be difficult to do is to have the
>>> headers on the second row.
>>>
>>> On Sun, Nov 30, 2008 at 3:23 AM, <david.jobet at free.fr> wrote:
>>>
>>>> Now I'm confused, what exactly are you suggesting ?
>>>>
>>>> I've never used delegates previously, but my understanding was : delegates
>>>> are used to paint things in a different way.
>>>> Is there another use ?
>>>> So unless there is another use I don't really understand how I can use them
>>>> and I don't know what for ?
>>>> And how is it going to solve my problem ? (Which is to display my "control
>>>> filtering" widgets above the header of the table ?)
>>>>
>>>> Something like :
>>>> |combo1|lineedit2|...|comboP|
>>>> |header1|header2|...|headerP|
>>>> |data11  |data12  |...|data1P  |
>>>> |data21  |data22  |...|data2P  |
>>>> |...          |...          |...|...           |
>>>> |dataN1  |dataN2 |...|dataNP  |
>>>>
>>>> Thanks
>>>>
>>>> David
>>>>
>>>> ----- Mail d'origine -----
>>>> De: Tiago Correia <tiago at cnotinfor.pt>
>>>> À: david jobet <david.jobet at free.fr>
>>>> Envoyé: Sun, 30 Nov 2008 03:13:58 +0100 (CET)
>>>> Objet: Re: qtableview : is it possible to add an extra "filter row" above
>>>> the header ?
>>>>
>>>> OK, so my guess is that you  will just need to extend the view class, so
>>>> that when you get an index for row 0, you change it to row 1. Then you
>>>> could
>>>> use delegates for these index on row 0.
>>>>
>>>> On Sun, Nov 30, 2008 at 2:05 AM, <david.jobet at free.fr> wrote:
>>>>
>>>> > No, as I said, I don't want to put it into row 0, because I want to
>>>> > separate the "filtering" from the content.
>>>> > The filtering being only a view/proxy thing, the model must not know
>>>> > anything about it.
>>>> >
>>>> > ----- Mail d'origine -----
>>>> > De: Tiago Correia <tiago at cnotinfor.pt>
>>>> > À: Qt Interest <qt-interest at trolltech.com>
>>>> > Envoyé: Sun, 30 Nov 2008 02:44:45 +0100 (CET)
>>>> > Objet: Re: qtableview : is it possible to add an extra "filter row" above
>>>> > the header ?
>>>> >
>>>> > Hi,
>>>> > Maybe a solution, might just by building special delegates, that for the
>>>> > indexes of row 0, will have a special beahviour.
>>>> >
>>>> > Also the model should reflect this, so for the row 0,the QIndexItem(s)
>>>> > should be different.
>>>> >
>>>> > On Sun, Nov 30, 2008 at 12:58 AM, <david.jobet at free.fr> wrote:
>>>> >
>>>> > > Hello,
>>>> > >
>>>> > > I hope I'm not too off here, I think I recall seeing it somewhere in
>>>> the
>>>> > qt
>>>> > > documentation, but I cannot find it again.
>>>> > >
>>>> > > To explain in more details :
>>>> > > - I have a table view with a custom model and a qsortfilterproxymodel
>>>> > > between the 2
>>>> > > - for each column of my table I want to add a control (a lineedit or a
>>>> > > combo) to be able to control the filtering of the content of my
>>>> tableview
>>>> > > - I want those controls to always be aligned with the table's column
>>>> > layout
>>>> > >
>>>> > > I could do a hack somewhere and make row 0 contain those controls, but
>>>> > I'd
>>>> > > prefer to separate the filtering controls from the table.
>>>> > > It would be great to be able to put those controls just above the
>>>> header.
>>>> > >
>>>> > > I guess I could put those controls above the table and resize them when
>>>> > my
>>>> > > table's header is resized, but I'm lazy ;-)
>>>> > > Do you know if qt's tableview/treeview have support for it ?
>>>> > >
>>>> > > Thanks
>>>> > >
>>>> > > David
>>>> > >
>>>> > > --
>>>> > > To unsubscribe - send a mail to qt-interest-request at trolltech.com with
>>>> > > "unsubscribe" in the subject or the body.
>>>> > > List archive and information: http://lists.trolltech.com/qt-interest/
>>>> > >
>>>> > >
>>>> >
>>>> >
>>>> > --
>>>> > Tiago Correia
>>>> > chief technology officer
>>>> >
>>>> > cnoti inovação & desenvolvimento – Aprendizagem enRiquecida pela
>>>> Tecnologia
>>>> > www.cnotinfor.pt
>>>> > Telefone: +351 239 499 231
>>>> >
>>>> > Subscreva gratuitamente a nossa Newsletter BICA – Boletim informativo de
>>>> > Interactividade, Comunicação e Aprendizagem
>>>> >
>>>> >
>>>>
>>>>
>>>> --
>>>> Tiago Correia
>>>> chief technology officer
>>>>
>>>> cnoti inovação & desenvolvimento – Aprendizagem enRiquecida pela Tecnologia
>>>> www.cnotinfor.pt
>>>> Telefone: +351 239 499 231
>>>>
>>>> Subscreva gratuitamente a nossa Newsletter BICA – Boletim informativo de
>>>> Interactividade, Comunicação e Aprendizagem
>>>>
>>>>
>>>
>>>
>>> --
>>> Tiago Correia
>>> chief technology officer
>>>
>>> cnoti inovação & desenvolvimento – Aprendizagem enRiquecida pela Tecnologia
>>> www.cnotinfor.pt
>>> Telefone: +351 239 499 231
>>>
>>> Subscreva gratuitamente a nossa Newsletter BICA – Boletim informativo de
>>> Interactividade, Comunicação e Aprendizagem
>>>
>>> --
>>> To unsubscribe - send a mail to qt-interest-request at trolltech.com with "unsubscribe" in the subject or the body.
>>> List archive and information: http://lists.trolltech.com/qt-interest/
>>>
>>>
>>
>>
>>
>> --
>> Regards,
>> Anthony
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>>
>
>
>
> --
> Regards,
> Anthony
>
>



-- 
Regards,
Anthony

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list