Unsolved How to avoid overlaping QComboBox items
-
I use a general css file for all the widget theme.
QComboBox { color: #ffffff; background-color: #d2a6ff; selection-background-color: #8000ff; outline: 0; font-size: 13pt; font-family: Vazir; } QComboBox QAbstractItemView { color:#ccc; background-color:#ba75ff; border:none; selection-background-color:#8000ff; selection-color: #ccc; height: 30px; }
-
Hi,
Do you mean the white text on the right ?
-
My ComboBox items are checkable. I happened to have this rare behavior on other comboBoxes.
When I catch evenFilter mouse click on one of them it goes away. But on comboBox which is checkable the problem stays.
-
I'm really sorry if I couldn't find a way to show the picture properly.
-
In that's case, can you provide a minimal compilable code sample that uses that style sheet and triggers your issue ?
-
I made a dialog with two comboBoxes and assign the css file but there isn't any errors.
My actual program consist a centeral tab with in other dialog classes placed there.When i run the dialog class by itself there is no errors. But when i run the main program and use it as a tab errors raise.
Also there is another issue when i add items to database on another tabs when the comboBoxes tab is open doesn't get updated.
i wrote piece of code which is eventFilter on mouse click on combos and calling a method for refreshing the model of combos. Is there any way to refresh the form without clicking ? -
Hello. Thanks for response. I know about MVC since i study Django a little but i don't know how to implement that in pyqt and sqlite. here is my update comboBox code i have to call the method each time to update the view please give me a practical example with code .
def updCombos(self): model = QtSql.QSqlQueryModel() qry = QtSql.QSqlQuery() qry.prepare("SELECT Address FROM PlcAddress WHERE ID NOT IN (SELECT plcAddr_id FROM PlcOuts)") if(qry.exec()): model.setQuery(qry); self.comboBoxAddr.setModel(model) qry1 = QtSql.QSqlQuery() cell1 = [] qry1.prepare ("SELECT * FROM plcValue"); if( qry1.exec ()): while qry1.next() : if str(qry1.value(1)) not in cell1 : cell1.append(str(qry1.value(1))) for index, element in enumerate(cell1): if self.comboBoxInput.findText(element) == -1 : self.comboBoxInput.addItem(element) item = self.comboBoxInput.model().item(index, 0) item.setCheckState(QtCore.Qt.Unchecked)
So this method is just for showing as you said i have to make a universal model for inserting and selecting and bind it to view how could i implement that i already google search and bump into QAbstractTableModel. I'm really confused but i know the MVC is right way to deal with database here is database insert from other class :
qry = QtSql.QSqlQuery() qry.prepare("insert into PlcAddress(Address) values ('"+self.lineEditAddr.text()+"')")
-
I made a separate class and yet again the view does'nt get updated after insertion on another form:
import DbConnection from PyQt5 import QtCore,QtSql class ComboModel(QtCore.QAbstractListModel): def __init__(self, parent=None, *args): super(ComboModel, self).__init__() # The data would normally be read from a database (not using the Qt SQL classes) self.data = [] self.conn = DbConnection self.conn.createConnection() model = QtSql.QSqlQueryModel() qry = QtSql.QSqlQuery() qry.prepare("SELECT Address FROM PlcAddress WHERE ID NOT IN (SELECT plcAddr_id FROM PlcOuts)") if(qry.exec()): while (qry.next()): self.data.append(qry.value(0)) def rowCount(self, parent): return len(self.data) def data(self, index, role): if role ==QtCore.Qt.DisplayRole: row = index.row() return self.data[row] def insertRow(self,row): qry = QtSql.QSqlQuery() qry.prepare("insert into PlcAddress(Address) values ('"+row+"')") if qry.exec(): return True else: return False def removeRow(self,index): qry = QtSql.QSqlQuery() qry.prepare("delete from PlcAddress where ID = ?") qry.addBindValue(index) if qry.exec(): return True else: return False
-
-
Your
data()
method has no route to return anything ifrole
is notDisplayRole
. Suggest you address. -
Your
insertRow()
&deleteRow()
methods fail to notify the outside world (i.e. the view) when it is inserting/deleting rows. This is why the view does not update. If you override a method please read the documentation, e.g. https://doc.qt.io/qt-5/qabstractitemmodel.html#insertRows
In either case, you will need to call
beginInsertRows()
andendInsertRows()
to notify other components that the model has changed.This has nothing to do with whether the view is on another form, which is what you implied.
-
-
I have no idea how to use it please give me some practical example . I guess my class skeleton is completely wrong.