PDA

View Full Version : How to turn off this annoying feature of QColumnView?



jwieland
16th July 2009, 22:13
Hi all,

I use a QStandardItemModel coupled with QColumnView to display a list of simple hierarchal tree structure. My view has 2 columns, rows on the second columns are children of a item on first column. When user select a item/row on column 1, children of that item/row will be displayed on second column. Now here comes the annoying behavior of the QColumnView: although my list has only 2 columns, whenever user click on an item of the second column, it automatically rolls further to the third column on the right (which is empty).

How do I disable this annoyed feature so that even if user click on a row in second column, the view does not automatically roll horizontally?

Thank you for all your help.

wysota
16th July 2009, 22:51
Try reimplementing QColumnView::createColumn() and returning 0. But in general it might be easier for you to substitute the column view with two list views. After all, the column view is for something different...

jwieland
17th July 2009, 15:40
Thanks Wysota. That what I will do (using 2 lists). BTW, Could you elaborate on what QColumnView is intended for?

wysota
17th July 2009, 16:01
It's a widget originating on Mac for showing filesystem contents. The final column is meant to show a preview of a node (file) chosen in the previous column.

LarryERamey
2nd September 2010, 19:06
I attempted to do exactly this....and it dies on me.



namespace systemoutliner
{
class MyColumnView : public QColumnView
{

Q_OBJECT

public:

MyColumnView(QWidget* parent=NULL);
~MyColumnView();
protected:
virtual QAbstractItemView * createColumn ( const QModelIndex & index );

};
}


namespace systemoutliner
{
MyColumnView::MyColumnView(QWidget* parent):
QColumnView(parent)
{
}
MyColumnView::~MyColumnView()
{
}

QAbstractItemView* MyColumnView::createColumn ( const QModelIndex &)
{
return NULL;
}
}


And when I try to connect a Model to this view I get this error:

QObject::connect: Cannot connect (null)::clicked(QModelIndex) to systemoutliner::MyColumnView::_q_clicked(QModelInd ex)
QObject::connect: Cannot connect (null)::activated(QModelIndex) to systemoutliner::MyColumnView::activated(QModelInde x)
QObject::connect: Cannot connect (null)::clicked(QModelIndex) to systemoutliner::MyColumnView::clicked(QModelIndex)
QObject::connect: Cannot connect (null)::doubleClicked(QModelIndex) to systemoutliner::MyColumnView::doubleClicked(QModel Index)
QObject::connect: Cannot connect (null)::entered(QModelIndex) to systemoutliner::MyColumnView::entered(QModelIndex)
QObject::connect: Cannot connect (null)::pressed(QModelIndex) to systemoutliner::MyColumnView::pressed(QModelIndex)




Any ideas?

tbscope
2nd September 2010, 19:16
Your code doesn't show where these connections are made.

LarryERamey
2nd September 2010, 19:45
sorry...



MyColumnView *columnView = new MyColumnView();
//QColumnView* columnView = new QColumnView();
ColumnModel *columnModel = new ColumnModel(inspectorGadget);
columnView->setFocusPolicy(Qt::NoFocus);
columnView->setModel(columnModel);


Line 5 explodes.....

ColumnModel is my own QAbstractModel class, but it works just fine with the default QColumnview.

Thanks,
Larry

ChrisW67
2nd September 2010, 22:10
You still don't show where these connect() calls are being made. The error messages are coming from using a null pointer as the first argument to the connect() calls listed.

LarryERamey
2nd September 2010, 22:42
well.... I didn't write the connect calls that are failing? I'm inheriting from a QAbsractItemModel and I'm overloading a QColumnView.

None of those pointers are NULL in the debugger when I make that setModel call so I am a bit puzzled. I guess I'll have to compile the Qt libs debug so I can step into them and see where is exploding.

wysota
3rd September 2010, 07:41
You are returning a null pointer from QColumnView::createColumn() reimplementation so no wonder you get such messages. You have to return a widget there. You can hide it afterwards if you don't want it but it has to be there.

LarryERamey
3rd September 2010, 16:59
Ahhh.....

That is a bummer since your original suggestion was to return a 0. I have opened the QColumnView.cpp and yeah, its pretty obvious that returning a NULL in that function is going to blow up the world.....

I'm looking right now, but does anyone have a quick suggestion to turn off the preview column in QColumnView?

wysota
3rd September 2010, 17:38
I have given you a suggestion already. Hide the column.