PDA

View Full Version : Enabling scroll bars in disabled QTableView



Koas
8th October 2009, 22:13
Hi all!

I have a QTableView that is disabled, but I'd like the user to still be able to see the data in the view using the scroll bars. The problem is that since the view is disabled the scrollbars are disabled as well, so no scrolling is possible.

I have tried subclassing the view and installing an event filter in the scroll bar widgets so they can ignore the enabled change event, but with no success.


myTableView::myTableView(QWidget *parent)
: QTableView(parent)
{
this->horizontalScrollBar()->installEventFilter(this);
this->verticalScrollBar()->installEventFilter(this);
}

bool myTableView::eventFilter(QObject *o, QEvent *e)
{
if(e->type()==QEvent::EnabledChange)
return true;
else return false;
}

Is there a way to keep the scroll bars enabled while the QTableView is disabled?

Thanks a lot! :)

yogeshgokul
9th October 2009, 06:12
A quick work around is you can make table view non-editable and non-selectable and non-focusable. Then it will look like disabled.
Call these functions:

tableView->setSelectionMode(QAbstractItemView::NoSelection);
tableView->setFocusPolicy( Qt::NoFocus);

Koas
9th October 2009, 11:39
Thanks yogeshgokul, it works fine!! :)