Voo
Voo

Reputation: 30216

pyqt Window similar to Win32 style

I'm trying to port a Win32 app to Python using pyqt for the GUI, but I can't seem to get a simple window with a text label and edit field such as the following simple Win32 style (basically WS_EX_CLIENTEDGE):

Example

I played with setFrameStyle (ie using different styles and sunken - and then for a good measure all other sensible combinations) of the two widgets and used setContentsMargins() to zero to get it to fill all the space, but the qt window still looks quite different with regard to the border.

Upvotes: 2

Views: 1440

Answers (2)

Jo Are By
Jo Are By

Reputation: 3433

I get pretty close with the following (using QtGui.QFrame.WinPanel):

import sys
from PySide import QtGui, QtCore

class Example(QtGui.QWidget):

    def __init__(self):
        super(Example, self).__init__()

        self.initUI()

    def initUI(self):
        label = QtGui.QLabel("Test")
        label.setAlignment(QtCore.Qt.AlignCenter)
        label.setFrameStyle(QtGui.QFrame.WinPanel | QtGui.QFrame.Sunken)

        edit = QtGui.QTextEdit()
        edit.setFrameStyle(QtGui.QFrame.WinPanel | QtGui.QFrame.Sunken)
        edit.setText("Some text")
        edit.moveCursor(QtGui.QTextCursor.MoveOperation.End)

        vbox = QtGui.QVBoxLayout()
        vbox.setContentsMargins(1, 1, 1, 1)
        vbox.setSpacing(1)
        vbox.addWidget(label)
        vbox.addWidget(edit)

        self.setLayout(vbox)

        self.setGeometry(300, 300, 300, 150)
        self.setWindowTitle('Window Title')
        self.show()

def main():

    app = QtGui.QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

QFrame docs has an excellent overview of different frame styles.

To get closer than setFrameStyle allows, you need to paint you own widgets/panels, or use something other than QT.

wxPython

pywin32

Upvotes: 1

Giacomo Lacava
Giacomo Lacava

Reputation: 1823

You are probably not using the right style. Have a look at the documentation for QStyle.

Upvotes: 0

Related Questions