Search code examples
resizepyqt4qpushbutton

Why does QPushButton not respect absolute pixel size?


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

I have deloped a customer dropdown menu that will expand down wards and show select buttons, on my dev system this looks 9as designed) something like this: enter image description here

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

enter image description here

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. They "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].resize(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 buttons not respect the QSize() as assigned?

I have started a new thread in the Qt Forum at and will make sure that replies are cross populated between the two threads!


Solution

  • And turns out, I have found the solution to my problem here: https://forum.qt.io/topic/78752/how-to-place-widgets-by-specifying-positions-in-qframe

    I changed my QPushButton line to include the parent which resolved the issue: self.drpbtns.append(QtGui.QPushButton(_name,self.parent))