سؤال

وأنا الحصول على بعض غرابة مع QtRuby عند استخدام TableWidget. الأحمال الجدول القطعة، ولكن عند النقر على العناصر في الصف، وخطأ التقسيم التطبيق وحوادث تحطم الطائرات.

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

ووالمتتبع الخلفي يبدو ان هذا يعني أنه قصف في 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

إذا كنت تجاوز mousePressEvent وmouseMoveEvent، وهذه الأنواع من الحوادث لم يعد يحدث. أفعل شيئا خطأ هنا، أو يمكنني الطباشير هذا الأمر بمثابة خطأ في QtRuby؟

وأنا على fedora11، مع تثبيت الحزم التالية:

وQtRuby-4.4.0-1.fc11.i586 روبي 1.8.6.369-1.fc11.i586

وتحدث هذه الحوادث أيضا عند تشغيل البرنامج النصي على ويندوز.

هل كانت مفيدة؟

المحلول

وأنت كنت تستخدم كيو تي :: TableWidget عند يجب استخدام كيو تي :: TableView. التعليمة البرمجية التالية إصلاح تحطم بالنسبة لي. بالإضافة إلى التحول من كيو تي :: TableWidget إلى كيو تي :: TableView، وأنا أيضا ل Reimplemented طريقة مؤشر، فقط في حالة. :)

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top