Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Why does QPushButton not respect absolute pixel size?



  • I'm working on an application that's running on an embedded device with a touch screen LCD. For my dev setup, I have setup a Xephyr window with the matchbox WM at the same resolution as the LCD on the end device (1280x800).

    I have developed a custom drop-down menu that will expand downwards and show select buttons, on my dev system this looks as designed) something like this:

    7b9bfde6-56c0-4a03-bdc4-53dfece5e858-image.png

    Where on the end device, the button for some reason fills the whole window as can be seen here:

    3b3982d3-009e-4222-b439-423173342edb-image.png

    The functionality seems there but even though fix pixel sizes are used for the button size, it seems to take up the space of the whole window. The "drop-down" buttons are created from a list like:

    btn_size = QtCore.QSize(206,57)
    
            for n in btnlist:
                _name = str(n)
                self.drpbtns.append(QtGui.QPushButton(_name))
                self.drpbtns[i].clicked.connect(lambda checked, v=_name: func(v))
                self.drpbtns[i].setFixedSize(btn_size) 
                self.drpbtns[i].move(x,y+(i*(self.drpbtns[i].height()-1)))
                self.drpbtns[i].setStyleSheet('background-color: rgb(255,255,255); \
                                               border: 1px solid rgb(216,216,216); \
                                               color: rgb(92,92,92); \
                                               font: bold 22pt "Avenir"')
                self.drpbtns[i].setFlat(True)
    
    
                i = i+1
    

    Why would the button not respect the FixedSize constraints?
    I have not been able to create a simple application that duplicates the problem as the problem only appears on the target device (and not on my dev setup - which is odd as well - I'm running my dev setup in a container attempting to create an env as similar as possible(Ubuntu Xenial 16.04, PyQt4, matchbox WM). Fix pixel sizes can be used as there is no need to support different window sizes/positions as the single screen is all the UI will show.

    I have already started a thread regarding this on Stackoverflow and I was suggested to replace .resize(btn_size) with .setFixedSize(btn_size) which didn't yield the expected effect though. As for the two threads, I'll keep them in sync, i.e. I'll sync any updates to both threads!

    Thanks for any assistance!



  • @SGaist Yes, Matchbox is running as well on the device.
    I think I just figured the issue out, it's because my drop down buttons were missing the parent.
    GFurether testing has to be done but a quick test with using self.drpbtns.append(QtGui.QPushButton(_name,self.parent)) instead has shown progress! I found the hint for this here: https://forum.qt.io/topic/78752/how-to-place-widgets-by-specifying-positions-in-qframe


  • Lifetime Qt Champion

    Hi,

    Do you mean you have Matchbox running as well on your device ?



  • @SGaist Yes, Matchbox is running as well on the device.
    I think I just figured the issue out, it's because my drop down buttons were missing the parent.
    GFurether testing has to be done but a quick test with using self.drpbtns.append(QtGui.QPushButton(_name,self.parent)) instead has shown progress! I found the hint for this here: https://forum.qt.io/topic/78752/how-to-place-widgets-by-specifying-positions-in-qframe


  • Lifetime Qt Champion

    Without parent, they are top level widgets and depending on your WM settings will be shown full screen.



  • @SGaist Yes Thank! It all makes sense now!