Python Forum
[PyQt] Number of characters in QLabel
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Number of characters in QLabel
#1
I'm trying out Qt4 and just want to print out a string in a window. Now, the string is clipped. All characters are not printed. So what am I missing?
FYI, I'm using python 2.7 on Ubuntu dist.

import sys
from PyQt4 import QtGui
from PyQt4 import QtCore

class ProdTestMonitor(QtGui.QMainWindow):

    def __init__(self):
        super(ProdTestMonitor, self).__init__()
        self.setGeometry(100, 30, 500, 300)
        self.initUI()

    def initUI(self):

        comPortLbl = QtGui.QLabel(self)
        comPortLbl.move(20, 100)
        comPortLbl.setText('This line is just to long:')

def main():
    app = QtGui.QApplication(sys.argv)
    frame = ProdTestMonitor()
    frame.show()
    sys.exit(app.exec_())

if __name__ == "__main__":
    main()
Thanks in advance.
Reply
#2
You are using the default size of the label, which is too short for your string. Just add something like:

        comPortLbl.resize(400, 20)

Also, since you are beginning you should work with Qt5 instead of Qt4. It will help maintaining your applications in the future.
Reply
#3
OK, that simple Blush.

Thank You for your tip.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Scaling text QLabel following display mode windows '100%, 125% ...) VIGNEAUD 2 2,261 Jul-07-2021, 06:38 PM
Last Post: deanhystad
Question [PyQt] CSS Styling for a QLabel inside a QListWidget Alfalfa 2 5,146 Nov-30-2020, 02:59 AM
Last Post: Alfalfa

Forum Jump:

User Panel Messages

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