moskalak
moskalak

Reputation: 271

Disable editing of QTableView in rubyqt

I'm trying to disable editing of QTableView in rubyqt. It's supposed to be done by setting triggers to QAbstractView::NoEdiTriggers:

TableView.setEditTriggers(QAbstractView::NoEditTriggers);

The trouble is, rubyqt doesn't recognize Qt::AbstractView:

irb(main):008:0> require 'Qt4'
=> true
irb(main):009:0> Qt::AbstractView
NameError: uninitialized constant Qt::AbstractView
    from (irb):9:in `const_missing'
    from (irb):9
    from /usr/bin/irb:12:in `<main>'

Is there another way to disable editing with ruby and qt?

EDIT Oh, and outside of irb:

searcher.rb:72:in `const_missing': uninitialized constant Qt::AbstractView (NameError)

And searcher.rb:72: @ui.tableView.setEditTriggers(Qt::AbstractView::NoEditTriggers)

Changing it to (Qt::AbstractView.NoEditTriggers) doesn't work, neither.

Upvotes: 2

Views: 191

Answers (1)

tkroman
tkroman

Reputation: 4798

require 'Qt4'

Qt::Application.new(ARGV) do
    Qt::Widget.new do

        self.window_title = 'Hello QtRuby v1.0'
        resize(200, 100)

        button = Qt::PushButton.new('Quit') do
            connect(SIGNAL :clicked) { Qt::Application.instance.quit }
        end

        tv = Qt::TableView.new do
          setEditTriggers(Qt::TableView::NoEditTriggers)
        end

        tm = Qt::StandardItemModel.new(1, 1) do
          setItem(0,0,Qt::StandardItem.new("aaa"))
        end

        tv.setModel tm

        self.layout = Qt::VBoxLayout.new do
            add_widget(tv, 0, Qt::AlignRight)
            add_widget(button, 0, Qt::AlignCenter)
        end

        show
    end

    exec
end

The main idea is that if no Abstract class from Qt is binded to Ruby, try looking for it's ancestors or implementations.

Upvotes: 2

Related Questions