RubyQt rompiendo en QTableWidget
-
20-09-2019 - |
Pregunta
Me estoy poniendo un poco de extrañeza con QtRuby cuando se utiliza un TableWidget. Las cargas de widgets mesa, pero al hacer clic en los elementos de la fila, las violaciones de segmento de aplicaciones y los accidentes.
require 'Qt4'
class SimpleModel < Qt::AbstractTableModel
def rowCount(parent)
return 1
end
def columnCount(parent)
return 1
end
def data(index, role=Qt::DisplayRole)
return Qt::Variant.new("Really Long String") if index.row == 0 and index.column == 0 and role == Qt::DisplayRole
return Qt::Variant.new
end
end
Qt::Application.new(ARGV) do
Qt::TableWidget.new(1, 1) do
set_model SimpleModel.new
show
end
exec
end
El trazado inverso parece dar a entender que se trata de bombardeos en mousePressEvent
#6 0x01624643 in QAbstractItemView::pressed(QModelIndex const&) () from /usr/lib/libQtGui.so.4
#7 0x016306f5 in QAbstractItemView::mousePressEvent(QMouseEvent*) () from /usr/lib/libQtGui.so.4
Si puedo reemplazar mousePressEvent y mouseMoveEvent, este tipo de accidentes no suceden. ¿Estoy haciendo algo mal aquí, o puedo tiza esto como un error en QtRuby?
Estoy en fedora11, la instalación de los siguientes paquetes:
QtRuby-4.4.0-1.fc11.i586 ruby-1.8.6.369-1.fc11.i586
Estos accidentes también ocurren cuando se ejecuta la secuencia de comandos en Windows.
Solución
Usted está utilizando un Qt :: TableWidget cuando se debe utilizar un Qt :: TableView. El siguiente código fija el choque para mí. Además de un cambio de Qt :: TableWidget a Qt :: TableView, también Reimplementado el método del índice, por si acaso. :)
require 'Qt4'
class SimpleModel < Qt::AbstractTableModel
def rowCount(parent)
return 1
end
def columnCount(parent)
return 1
end
def data(index, role=Qt::DisplayRole)
return Qt::Variant.new("Really Long String") if index.row == 0 and index.column == 0 and role == Qt::DisplayRole
return Qt::Variant.new
end
def index(row, column, parent)
if (row > 0 || column > 0)
return Qt::ModelIndex.new
else
return createIndex(row, column, 128*row*column)
end
end
end
Qt::Application.new(ARGV) do
Qt::TableView.new do
set_model SimpleModel.new
show
end
exec
end