Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, May 2007
QTableView read-only mode


Message 1 in thread

Hi!

Is it possible to make QTableView working in read-only mode ( e.g. you
can't edit cells ).

Currently I'm using such a trick:

============QCustomTableView.h===============
#include <QTableView>

class QCustomTableView : public QTableView
{
     Q_OBJECT;
public:
     QCustomTableView( QWidget *parent = 0 );
protected:
     virtual bool edit( const QModelIndex & index, EditTrigger trigger,
QEvent * event  ); };
===========QCustomTableView.cpp=================

#include "QCustomTableView.h"

QCustomTableView::QCustomTableView( QWidget *parent )
: QTableView( parent )
{
}

QCustomTableView::~QCustomTableView()
{
}

bool QCustomTableView::edit( const QModelIndex & index, EditTrigger
trigger, QEvent * event ) {
     return true;
}

I've discussed it there:
http://www.qtforum.org/thread.php?threadid=20480

But noone helped me there :(

-- 
 [ signature omitted ] 

Message 2 in thread

Hi Ilia,

QTableView can be set to no-edit if you use the void *setEditTriggers 
<http://doc.trolltech.com/4.3/qabstractitemview.html#editTriggers-prop>* 
( EditTriggers /triggers/ ) function...

The Enum you are looking for is: QAbstractItemView::NoEditTriggers

It's in this documentation: 
http://doc.trolltech.com/4.3/qabstractitemview.html

Hope this helps,
K.

Ilia N Ternovich wrote:
> Hi!
>
> Is it possible to make QTableView working in read-only mode ( e.g. you
> can't edit cells ).
>
> Currently I'm using such a trick:
>
> ============QCustomTableView.h===============
> #include <QTableView>
>
> class QCustomTableView : public QTableView
> {
>      Q_OBJECT;
> public:
>      QCustomTableView( QWidget *parent = 0 );
> protected:
>      virtual bool edit( const QModelIndex & index, EditTrigger trigger,
> QEvent * event  ); };
> ===========QCustomTableView.cpp=================
>
> #include "QCustomTableView.h"
>
> QCustomTableView::QCustomTableView( QWidget *parent )
> : QTableView( parent )
> {
> }
>
> QCustomTableView::~QCustomTableView()
> {
> }
>
> bool QCustomTableView::edit( const QModelIndex & index, EditTrigger
> trigger, QEvent * event ) {
>      return true;
> }
>
> I've discussed it there:
> http://www.qtforum.org/thread.php?threadid=20480
>
> But noone helped me there :(
>
>   
begin:vcard
begin:vcard
fn:Kavindra Palaraja
n:Palaraja;Kavindra
org:Trolltech ASA;Documentation
email;internet:kdpalara@xxxxxxxxxxxxx
title:Junior Technical Writer
x-mozilla-html:FALSE
version:2.1
end:vcard


Message 3 in thread

Ilia N Ternovich schrieb:
> Hi!
> 
> Is it possible to make QTableView working in read-only mode ( e.g. you
> can't edit cells ).
> [...]
> I've discussed it there:
> http://www.qtforum.org/thread.php?threadid=20480
> 
> But noone helped me there :(

Your question in Qt Forum is about QTableWidget, but you showed us code 
using a QTableView. Please look that up if you're not sure about the 
differences of these two.
With QTableView it's the task of your model to allow or deny cell 
editing; see QAbstractItemModel::flags() and ::setData().

Martin

-- 
 [ signature omitted ] 

Message 4 in thread

On Fri, 11 May 2007 14:28:37 +0200
Martin Gebert <Martin.Gebert@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

> Your question in Qt Forum is about QTableWidget, but you showed us code 
> using a QTableView.

I suppose QTableWidget is the child of the QTableView ;-)
If *setEditTriggers works with QAbstractItemView, it will work
with QTableView and in it's own turn with QTableWidget :-)

> With QTableView it's the task of your model to allow or deny cell 
> editing; see QAbstractItemModel::flags() and ::setData().

The clear and fast solution was by Kavindra Palaraja. Anyhow, thank you
and Kavindra Palaraja for rapid response

P.S. Martin Gebert, please let me know if this mail was again delivered
directly to you instead of qt-mail list ( sorry for your troubles because
of my stupid mail-client )

-- 
 [ signature omitted ] 

Message 5 in thread

Ilia N Ternovich schrieb:
> I suppose QTableWidget is the child of the QTableView ;-)
> If *setEditTriggers works with QAbstractItemView, it will work
> with QTableView and in it's own turn with QTableWidget :-)

That's true. However, I wasn't aware of the editTriggers solution till 
today, as I'm used to control my views through the model whenever 
possible. Live and learn... ;-)

> The clear and fast solution was by Kavindra Palaraja. Anyhow, thank you
> and Kavindra Palaraja for rapid response

Well, that depends on what you want to achieve. Use what suits your case.

> P.S. Martin Gebert, please let me know if this mail was again delivered
> directly to you instead of qt-mail list ( sorry for your troubles because
> of my stupid mail-client )

No, this one went to the list, and anyhow I haven't received any direct 
mail from you sometime in the past. Namespace confusion? ;-)

Martin

-- 
 [ signature omitted ]