Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Disable a treewidget but allow scrollbars
QtWS25 Last Chance

Disable a treewidget but allow scrollbars

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ran_s
    wrote on last edited by ran_s
    #1

    Hi

    I have a QTreeWidget which has to be disabled but the user should be allowed to see the contents of it by providing scroll-bars. I have tried the following solution, with this I am able to see scroll-bar but it's not moving.

    View::View( QWidget* parent ) 
    {
    	this->horizontalScrollBar()->installEventFilter(this);
    	this->verticalScrollBar()->installEventFilter(this);
    }
    bool View::eventFilter( QObject *obj, QEvent *event )
    {
    	if( event->type() == QEvent::EnabledChange )
    		return true;
    	else 
    		return QObject::eventFilter(obj, event);
    }
    

    can anyone please suggest a solution. thanks in advance.

    JKSHJ 1 Reply Last reply
    0
    • R ran_s

      Hi

      I have a QTreeWidget which has to be disabled but the user should be allowed to see the contents of it by providing scroll-bars. I have tried the following solution, with this I am able to see scroll-bar but it's not moving.

      View::View( QWidget* parent ) 
      {
      	this->horizontalScrollBar()->installEventFilter(this);
      	this->verticalScrollBar()->installEventFilter(this);
      }
      bool View::eventFilter( QObject *obj, QEvent *event )
      {
      	if( event->type() == QEvent::EnabledChange )
      		return true;
      	else 
      		return QObject::eventFilter(obj, event);
      }
      

      can anyone please suggest a solution. thanks in advance.

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi @ran_s, and welcome to the Qt Dev Net!

      It sounds like you want to disable the items, but not the QTreeWidget itself. One way to to that is to remove the Qt::ItemIsEnabled flag from the QTreeWidgetItem:

      // Construct objects
      auto widget = new QTreeWidget;
      auto item = new QTreeWidgetItem(strings);
      
      // ...
      
      // Edit flags
      Qt::ItemFlags currentFlags = item->flags();
      item->setFlags(currentFlags & ~Qt::ItemIsEnabled);
      
      // Add item to widget
      widget->addTopLevelItem(item);
      

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ran_s
        wrote on last edited by
        #3

        @JKSH thank you for your suggestion, it solves my problem.
        as i was using QTreeView I could able to set flags by overriding QAbstractItemModel::flags()
        it is working fine.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved