2016-02-22 85 views
0

我創建了一個QTableView並設置其採用的是滑蓋編輯在列2單元我呼籲所有細胞openPersistentEditor 2欄的委託:爲什麼QTableView單元格在點擊時沒有被聚焦?

MinMaxSliderDelegate *minMaxSliderDelegate = new MinMaxSliderDelegate(this); 
table = new QTableView(); 
table->setModel(new ServoConfiguration(this)); 
table->setItemDelegate(minMaxSliderDelegate); 
for(int r=0; r<table->model()->rowCount(); r++) { 
    table->openPersistentEditor(table->model()->index(r,2)); 
} 

所以現在我有在永久陳列滑塊表第2列

我使用QStyledItemDelegate的子類來創建滑塊的代碼是:

QWidget *MinMaxSliderDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { 

if (index.column()==2) { 

    MinMaxSlider *editor = new MinMaxSlider(Qt::Horizontal, index.row(), parent); 
    editor->setAutoFillBackground(true); 
    editor->setFocusPolicy(Qt::StrongFocus); 
    editor->setMinimum(750); 
    editor->setMaximum(2000); 
    editor->setMinValue(1000); 
    editor->setMaxValue(1500); 
    connect(uiObj, SIGNAL(setMinToCurrentValue(int)), editor, SLOT(setMinValueToCurrentValue(int))); 
    connect(uiObj, SIGNAL(setMaxToCurrentValue()), editor, SLOT(setMaxValueToCurrentValue())); 

    return editor; 
} 

return QStyledItemDelegate::createEditor(parent, option, index); 

我的問題是,我需要知道當用戶通過我們編輯值滑塊(它應該有焦點)。我發現,如果我從表格單元格滑動到其左側的滑塊,則滑塊將變爲table->selectionModel()->currentIndex();返回的當前項目。但是,如果我單擊滑塊,則當前項目不會更改。我還發現,儘管我可以從單元格向左滑動滑塊,但我無法從滑塊中移出。

我相信我錯過了一些簡單的東西,但我會感謝一些幫助。

在它的事項的情況下,我設置爲StrongFocus在其構造滑塊和QModelView標誌爲滑塊的列有:Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;

回答

相關問題