确定TableView中选择的开始?

时间:2018-12-21 13:16:44

标签: qt qml

我的QML中有一个TableView:

#Top words after stemming operation

#collect vocabulary count

#create the object of tfid vectorizer

tfid_vectorizer = TfidfVectorizer("english")
#fit the vectorizer using the text data
tfid_vectorizer.fit(data['text'])
#collect the vocabulary items used in the vectorizer
dictionary = tfid_vectorizer.vocabulary_.items()

#Bar plot of top words after stemming
#lists to store the vocab and counts

vocab = []
count = []

#iterate through each vocab and count append the value to designated lists
for key, value in dictionary:
    vocab.append(key)
    count.append(value)

#store the count in pandas dataframe with vocab as index
vocab_after_stem = pd.Series(count, index=vocab)

#sort the dataframe
vocab_after_stem = vocab_after_stem.sort_values(ascending=False)

#plot of the top vocab
top_vocab = vocab_after_stem.head(20)
top_vocab.plot(kind = 'barh', figsize=(5,10), xlim = (15120,15145))

#Histogram of text length of each writer
def length(text):
    return length(text)

#Apply the function to each example
data['length'] = data['text'].apply(length)
data.head(10)

是否可以确定选择的开始和结束?

例如用户是从低索引到高索引还是从高索引到低索引选择项目。

1 个答案:

答案 0 :(得分:1)

您必须使用table.selection.forEach旁边table.selection的onSelectionChanged信号来实现一种计算所需索引的算法:

Connections {
    target: table.selection
    onSelectionChanged:{
        console.log("Change Selection")
        if(table.selection.count > 0){
            var start = table.rowCount;
            var end = 0;
            table.selection.forEach(function(rowIndex){
                if(rowIndex < start)
                    start = rowIndex;
                if(rowIndex > end)
                    end = rowIndex
            })
            console.log("start: ", start, "end: ", end)
        }
    }
}