[QtRuby 4.8.6] Cannot insert Qt::ComboBox in Qt::TableWidget
I was trying to embed several combo boxes in a table widget in the first column and in as many rows as possible. Whenever I executed the code below that never happened. If I set the table widget as the combo box parent it shows up on the upper left corner of the table widget not in row 1 column 1 or anywhere else. If I don't set any combo box parent widget, the combo box never is never displayed. No matter what I do all the table widget cells are common cells, none of them look or work like combo boxes. Does anybody know what I should do to embed those combo boxes in the table widget?
Code:
@table = Qt::TableWidget.new(@central_widget)
@table.objectName = 'tableWidget'
@table.geometry = Qt::Rect.new(250, 110, 340, 200)
@table.columnCount = 3
labels = ['Category', 'ID', 'Points']
column_items = []
combo_boxes = []
3.times {|n| column_items[n] = Qt::TableWidgetItem.new
column_items[n].text = labels[n]
@table.setHorizontalHeaderItem(n, column_items[n])
combo_boxes << Qt::ComboBox.new(@table)
combo_boxes[n].objectName = "comboBox_#{n+1}"
combo_boxes[n].maxVisibleItems = 4
combo_boxes[n].insertItems(0,['Dairy', 'Bread', 'Meat', 'Sauce'])
combo_boxes[n].sizeAdjustPolicy = Qt::ComboBox::AdjustToContents
@table.setCellWidget(n + 1, 1, combo_boxes[n])
}
@table.rowCount = 3 if @table.rowCount < 1
@table.resizeColumnsToContents
Re: [QtRuby 4.8.6] Cannot insert Qt::ComboBox in Qt::TableWidget
What you are looking for is an item delegate for the first column that uses a QComboBox as its editor.
See https://wiki.qt.io/Combo_Boxes_in_Item_Views for an example
Cheers,
_
Re: [QtRuby 4.8.6] Cannot insert Qt::ComboBox in Qt::TableWidget
Thank you for the hint, now I need to break my head trying to convert the example into some working QtRuby piece of code. I hope I manage to do it in a timely fashion...