Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to avoid overlaping QComboBox items
Forum Updated to NodeBB v4.3 + New Features

How to avoid overlaping QComboBox items

Scheduled Pinned Locked Moved Unsolved Qt for Python
qt for pythonpython
10 Posts 4 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • behruz montazeriB Offline
    behruz montazeriB Offline
    behruz montazeri
    wrote on last edited by
    #1

    Overlaping

    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;
    }
    
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you mean the white text on the right ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      behruz montazeriB 2 Replies Last reply
      0
      • SGaistS SGaist

        Hi,

        Do you mean the white text on the right ?

        behruz montazeriB Offline
        behruz montazeriB Offline
        behruz montazeri
        wrote on last edited by
        #3

        @SGaist

        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.

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Do you mean the white text on the right ?

          behruz montazeriB Offline
          behruz montazeriB Offline
          behruz montazeri
          wrote on last edited by
          #4

          @SGaist

          I'm really sorry if I couldn't find a way to show the picture properly.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            In that's case, can you provide a minimal compilable code sample that uses that style sheet and triggers your issue ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            behruz montazeriB 1 Reply Last reply
            0
            • SGaistS SGaist

              In that's case, can you provide a minimal compilable code sample that uses that style sheet and triggers your issue ?

              behruz montazeriB Offline
              behruz montazeriB Offline
              behruz montazeri
              wrote on last edited by behruz montazeri
              #6

              @SGaist

              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 ?

              1 Reply Last reply
              0
              • behruz montazeriB Offline
                behruz montazeriB Offline
                behruz montazeri
                wrote on last edited by behruz montazeri
                #7

                @Denni-0

                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()+"')")
                
                1 Reply Last reply
                0
                • behruz montazeriB Offline
                  behruz montazeriB Offline
                  behruz montazeri
                  wrote on last edited by behruz montazeri
                  #8

                  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
                  
                  
                  JonBJ 1 Reply Last reply
                  0
                  • behruz montazeriB behruz montazeri

                    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
                    
                    
                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @behruz-montazeri

                    1. Your data() method has no route to return anything if role is not DisplayRole. Suggest you address.

                    2. 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() and endInsertRows() 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.

                    behruz montazeriB 1 Reply Last reply
                    1
                    • JonBJ JonB

                      @behruz-montazeri

                      1. Your data() method has no route to return anything if role is not DisplayRole. Suggest you address.

                      2. 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() and endInsertRows() 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.

                      behruz montazeriB Offline
                      behruz montazeriB Offline
                      behruz montazeri
                      wrote on last edited by behruz montazeri
                      #10

                      @JonB

                      I have no idea how to use it please give me some practical example . I guess my class skeleton is completely wrong.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved