Python Forum
QComboBox doesn't display selection as long as it has not lost the focus
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QComboBox doesn't display selection as long as it has not lost the focus
#1
I am developing a PyQt5 application. It works properly on Linux platform but I meet an issue when running it on a Windows 10 platform. The trouble is with QComboBox. When the user selects an item in a QComboBox it is not displayed as long as the QComboBox has not lost focus. This means that the previously selected item text stays visible and the user has to click elsewhere in the windows to make the text of the newly selected item appear in the combo. Moreover, when hovering an item in the dropdown list of the combo, its text disappears (whitening of the selected line) Can somebody help me fixing this 2 issues ?
Reply
#2
This is not normal behavior in windows. Can you post a little example?
Reply
#3
Thank you for your answer.
My application has a main window that, in its __init__(), instantiates sub-dialogs. The trouble with the QComboBox doesn' exist in the subdialogs. The combo are working properly. The trouble occurs only in the main window.
Here below is the main.py then the MainWindows's __init__().


from PyQt5 import QtCore
from PyQt5.QtWidgets import QApplication
import sys
from view.MainWindow import MainWindow

 

if __name__=='__main__':
    current_exit_code=-12345678 
    app=QApplication(sys.argv)
    mainWindow=None
    while current_exit_code == -12345678 :
        translator = QtCore.QTranslator()
        app.installTranslator(translator)
        if mainWindow:
            mainWindow.close()
        #restart from beginning
        mainWindow = MainWindow(translator)
        MainWindow.show(mainWindow)
        current_exit_code=app.exec_()
        print('exit code is '+str(current_exit_code))
        
and an extract of the MainWindow's initialiszation

class MainWindow(QMainWindow,MainWindowUI.Ui_MainWindow):
    '''
    classdocs
    '''
    EXIT_CODE_REBOOT = -12345678

###################################################################################################################################     
    def __init__(self, translator,parent=None):
        super(MainWindow,self).__init__(parent)
        self.setupUi(self)
        self.translator=translator
        self.calculator=None
        
        'THIS IS FOR PYINSTALLER ONLY'
        'Folder structure is quite different when running in a bundle'
        'Please see pyinstaller’s documentation'
        self.frozen = 'not' 
        if getattr(sys, 'frozen', False): #return False if the attribute is not found
            self.frozen = 'yes'
            self.bundle_dir = sys._MEIPASS
            self.model = Model(self.bundle_dir)#we pass the path to database
            'the path to the translated .qm files'
            self.trad_path=os.path.join(self.bundle_dir ,'translate')
   
        else: 
            self.frozen='not'
            'l’import export is reserved to the frozen application (bundled)'
            self.actionImport_Export_Databases.setVisible(False)
            self.model = Model()
            'the path to the .qm translated files'
            (filepath,filename)=os.path.split(__file__)
            self.trad_path=os.path.join(filepath,'..','translate')
        
        
        self.controller = Controller(self.model) 
        self.unitSetter=UnitSetter(self.model,self)
        self.language_setter=LanguageSetter(self.model,self)
        if not self.model.language:
            self.language_setter.setModal(True)
            self.language_setter.show()  
        else: self.set_language(self.model.language[1]) 
        #IMPORTANT:
        #setting of locale is deported in showEvent as language is not ready at this stage of init'
        
        #colors must be set before all dialogs
        'due to the translation into util.init_hop_usage_dic , util should be created after setting the language'
        self.util=Utils(self.model)
    
        self.util.init_hop_usage_dic()
        self.util.init_yeast_form_dic()
        self.style_key_list=self.model.style_list
        self.set_active_colors() 
        self.create_constant_list()
        self.constant_setter=ConstantDialog(self.model,self.util,self.constant_list)
        self.maltDialog=MaltDialog(self.model,self.controller,self.util)
        self.malt_chooser=MaltChooser(self.model,self.controller,self.util,self)
        self.sugarDialog=SugarDialog(self.model,self.controller,self.util)
        self.hopDialog=HopDialog(self.model,self.controller,self.util)
        self.restDialog=RestDialog(self.model,self.controller, self.util)
        self.yeastDialog=YeastDialog(self.model,self.controller,self.util)
        self.recipeDialog = RecipeDialog(self.model,self.controller,self.util)
        self.colorDialog = ColorDialog(self.model,self.controller,self.util)
        self.ABV_calculator=ABVCalculator(self.model,self.controller, self.util)
        self.priming_calculator=PrimingCalculator(self.model,self.controller,self.util)
        self.equipmentDialog=EquipmentDialog(self.model,self.controller,self.util)
Reply
#4
I eventually found that it was only a styling issue. I mistakenly applied a color identical to the background-color on the selection.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] display content from left to right in QComboBox or QLineEdit mart79 2 452 May-30-2020, 04:38 PM
Last Post: Axel_Erfurt
  How to disable focus on Frame in Tkinter? szafranji 1 768 May-13-2020, 10:45 PM
Last Post: DT2000
  QComboBox for PyQt code gvin47 3 463 Apr-22-2020, 04:01 PM
Last Post: gvin47
  Tkinter focus catlessness 5 1,282 Apr-03-2020, 05:24 AM
Last Post: joe_momma
  Display and update the label text which display the serial value jenkins43 5 3,809 Feb-04-2019, 04:36 AM
Last Post: Larz60+
  Display more than one button in GUI to display MPU6000 Sensor readings barry76 4 1,220 Jan-05-2019, 01:48 PM
Last Post: wuf
  [PyQt] PyQt4 dynamic QComboBox littleGreenDude 4 2,214 Jan-02-2019, 07:22 PM
Last Post: littleGreenDude
  So lost mtndewwarrior 12 3,840 Sep-23-2018, 08:49 PM
Last Post: snippsat
  [PyQt] Get Data from QComboBox Ferris 0 1,723 Feb-28-2018, 04:59 AM
Last Post: Ferris
  [PyQt] How can I get special data from QComboBox()? Sophus 0 3,069 Jul-26-2017, 04:56 PM
Last Post: Sophus

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020