Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Disable a treewidget but allow scrollbars

    General and Desktop
    2
    3
    1182
    Loading More Posts
    • 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
      ran_s last edited by 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.

      JKSH 1 Reply Last reply Reply Quote 0
      • JKSH
        JKSH Moderators @ran_s last edited by

        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 Reply Quote 0
        • R
          ran_s last edited by

          @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 Reply Quote 0
          • First post
            Last post