[PYTHON] The problem that the width of the main window widens when setting long text in the status bar in the Qt app (PySide version)

Introduction

These tips are the way to solve the same problem with PySide as below! http://qiita.com/soramimi_jp/items/3d4e800e3d86ed216deb

Taisaku

Let's create a class that does not forcibly spread with PySide.

StatusLabel.py



# -*- coding: utf-8 -*-
from PySide import QtGui
class StatusLabel(QtGui.QLabel):

    def __init__(self,parent=None):
        super(StatusLabel,self).__init__(parent)

    def minimumSizeHint(self):
        sz = QtGui.QLabel.minimumSizeHint(self)
        sz.setWidth(0)
        return sz

Let's use it nicely in the main window.

mainwindow.py


# -*- coding: utf-8 -*-
from StatusLabel import StatusLabel
class MainWindow(QtGui.QMainWindow,Ui_MainWindow):

    def __init__(self, parent=None):

        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.statuslabel = StatusLabel("a long text......")
        self.statusBar.addWidget(self.statuslabel)

That's it.

It doesn't matter, but it's hard to go back and forth between C (++) and Python. ..

Recommended Posts

The problem that the width of the main window widens when setting long text in the status bar in the Qt app (PySide version)
About the problem that the python version of Google App Engine does not mesh