Setting setModel, and setView(QTableView*) for QComboBox;
All is ok, but cant to do QTableView wider then combobox width;
Width is the same as combobox:-(
How to make QTableView wodget wider?
Printable View
Setting setModel, and setView(QTableView*) for QComboBox;
All is ok, but cant to do QTableView wider then combobox width;
Width is the same as combobox:-(
How to make QTableView wodget wider?
Solved:
setMinimumWidth for QTableView
Thanks
But have other problem, cant to change in this QTableView - column width.
All columns have the same width, and it cant be changed by:
resizeColumnsToContents, setColumnWidth. Always the same:confused:
Try QHeaderView (accessible via QTableView::horizontalHeader()).
I´m joing to your thread, but I need a how to get a QComboBox with multple columns like VBasic does.
Hello,
I've just had the same problem, here's my solution :
Code:
ui->coilComboBox->setView(coilView); //set it to the comboBox before making changes coilView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); //fine tuning of some options coilView->setAutoScroll(false); ui->coilComboBox->setModel(model); //set the model coilView->resizeColumnsToContents(); //resise to content after setting model (needs data) coilView->resizeRowsToContents(); coilView->setMinimumWidth(coilView->horizontalHeader()->length()); //to have a good width on the drop down widget
Hope it helps :)
From Qt Assistant:
Example: (written in Python)Quote:
void QComboBox::setView ( QAbstractItemView * itemView ):
Sets the view to be used in the combobox popup to the given itemView. The combobox takes ownership of the view.
Note: If you want to use the convenience views (like QListWidget, QTableWidget or QTreeWidget), make sure to call setModel() on the combobox with the convenience widgets model before calling this function.
As with every solution, it comes with new problems. In the previous example, it is possible to set the QComboBox with any value from the QTable. Or, in other words, if you click the first value from the first row the QComboBox will show a different value as when you would click the second value from the first row.Code:
box.setObjectName('somename') model.setQuery('select something as somename, somethingother from somewhere') view.setModel(model) #Do with the view whatever you like view.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) view.setAutoScroll(False) view.resizeColumnsToContents() view.resizeRowsToContents() #view.setSortingEnabled(True) view.verticalHeader().setVisible(False) #Rownumbers view.setMinimumWidth(view.horizontalHeader().length()) #The important part: First set the model, then the view on the box box.setModel(model) box.setView(view)
I'm open to suggestions as how to solve that problem.