Class: Qt::TreeWidget

Inherits:
Object show all
Defined in:
lib/cosmos/gui/qt.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent = Qt::Application.activeWindow) ⇒ TreeWidget

Returns a new instance of TreeWidget.



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/cosmos/gui/qt.rb', line 334

def initialize(parent = Qt::Application.activeWindow)
  super(parent)

  # Create a sensible default handler for clicking the checkboxes
  # of a tree. If you check a node all the lower nodes get checked.
  # If you uncheck a node all the lower nodes get unchecked.
  # If you check a lower node all the parent nodes get checked.
  connect(SIGNAL('itemClicked(QTreeWidgetItem*, int)')) do |node, col|
    if node.checkState == Qt::Checked
      # Set all nodes below this to checked
      node.setCheckStateAll(Qt::Checked)

      # Set all the nodes above this to checked
      while node.parent
        node = node.parent
        node.setCheckState(0, Qt::Checked)
      end
    else
      # Set all nodes below this to unchecked
      node.setCheckStateAll(Qt::Unchecked)
    end
  end
end

Instance Method Details

#topLevelItemsObject

Yields each of the top level items (those without a parent).



359
360
361
362
363
# File 'lib/cosmos/gui/qt.rb', line 359

def topLevelItems
  topLevelItemCount.times do |index|
    yield topLevelItem(index)
  end
end