2017-07-19 78 views

回答

1

加入AT-最後我發現這樣做的2種方式。

  1. 通過設置使用QSignalMapper

第一種方法

QComboBox* mCombo = new QCombobox(); 
mComboBox->setProperty("row",(int) i); // i represents the row number in qtablewidget 

在處理函數,你在哪裏處理點擊QComboBox

int row = sender()->property("row").toInt(); 
的QComboBox
  • 財產

    第二種方法

    QSignalMapper *signalMapper= new QSignalMapper(this); //Create a signal mapper instance 
    
    for (each row in table) { 
        QComboBox* mCombo = new QComboBox(); 
        table->setCellWidget(row,col,combo);       
        connect(mCombo, SIGNAL(currentIndexChanged(int)), signalMapper, SLOT(map())); 
    
    /*connect each signal of QComboBox to signal Mapper slot (i.e map()) which in turns connected to the signal of signalMapper calling the SLOT associated with it (i.e rowFinder) */   
    
    signalMapper->setMapping(combo, (int)row); //assign mapping to each widgetusing set mapping 
    
    
    } 
    
    connect(signalMapper, SIGNAL(mapped(int)), 
         this, SLOT(rowFinder(int))); 
    

    功能:rowFinder(INT的rowIndex)

    int row = rowIndex; //here is the row indexof selected QComboBox 
    
  • +0

    正確的方法是使用QStyledItemDelegate子類,油漆組合框,並創建它作爲主編。一旦實現,你可以使用來自'table-> selectionModel()'('selectionChanged'和'currentChanged')的信號來截取你想要的任何東西(但是,我99.9999%肯定你所要做的是已經在代表內部可行) – IlBeldus

    相關問題