Results 1 to 3 of 3

Thread: [QtRuby 4.8.6] Cannot insert Qt::ComboBox in Qt::TableWidget

  1. #1
    Join Date
    Aug 2015
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default [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?

    Qt Code:
    1. @table = Qt::TableWidget.new(@central_widget)
    2. @table.objectName = 'tableWidget'
    3. @table.geometry = Qt::Rect.new(250, 110, 340, 200)
    4. @table.columnCount = 3
    5. labels = ['Category', 'ID', 'Points']
    6. column_items = []
    7. combo_boxes = []
    8. 3.times {|n| column_items[n] = Qt::TableWidgetItem.new
    9. column_items[n].text = labels[n]
    10. @table.setHorizontalHeaderItem(n, column_items[n])
    11. combo_boxes << Qt::ComboBox.new(@table)
    12. combo_boxes[n].objectName = "comboBox_#{n+1}"
    13. combo_boxes[n].maxVisibleItems = 4
    14. combo_boxes[n].insertItems(0,['Dairy', 'Bread', 'Meat', 'Sauce'])
    15. combo_boxes[n].sizeAdjustPolicy = Qt::ComboBox::AdjustToContents
    16. @table.setCellWidget(n + 1, 1, combo_boxes[n])
    17. }
    18. @table.rowCount = 3 if @table.rowCount < 1
    19. @table.resizeColumnsToContents
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  3. #3
    Join Date
    Aug 2015
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default 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...

Similar Threads

  1. Replies: 1
    Last Post: 10th November 2010, 15:18
  2. Replies: 0
    Last Post: 3rd November 2010, 17:43
  3. how to insert items in tableWidget
    By roncriss in forum Newbie
    Replies: 3
    Last Post: 24th July 2010, 18:10
  4. TableWidget
    By matulik in forum Newbie
    Replies: 6
    Last Post: 2nd May 2010, 19:47
  5. lineedit,combobox in tablewidget
    By beams in forum Newbie
    Replies: 0
    Last Post: 10th April 2010, 09:54

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.