Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. PyQt5: Text seems to overlap

PyQt5: Text seems to overlap

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 725 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zeankundev
    wrote on last edited by
    #1

    Hi, I wanted to make the QLabel on the bottom of a QLabel, somehow ended up having this.
    0417d5ac-3d1b-42bf-ae68-fe6f1ebed021-image.png
    main snippet:

    def main():
        app = QtWidgets.QApplication([])
        window = QtWidgets.QWidget()
        window.setWindowTitle("kabantu")
        label = QtWidgets.QLabel(window)
        pixel = QtGui.QPixmap.fromImage(QtGui.QImage("kabantu.png"))
        label.setPixmap(pixel)
        label.setFixedSize(380, 136)
        label.setScaledContents(True)
        titleLabel = QtWidgets.QLabel(window)
        titleLabel.setText("kabantu 26.04 lts installer")
        titleLabel.setStyleSheet("font-size: 20px;")
        titleLabel.setAlignment(QtCore.Qt.AlignCenter)
        font = titleLabel.font()
        font.setBold(True)
        layout = QtWidgets.QVBoxLayout()
        layout.setAlignment(QtCore.Qt.AlignCenter)
        layout.addWidget(label)
        layout.addWidget(titleLabel)
        window.setWindowIcon(QtGui.QIcon("./kabantu.png"))  
        window.setFixedSize(400, 200)
        window.show()
        app.exec_()
    
    JonBJ 1 Reply Last reply
    0
    • Z zeankundev

      Hi, I wanted to make the QLabel on the bottom of a QLabel, somehow ended up having this.
      0417d5ac-3d1b-42bf-ae68-fe6f1ebed021-image.png
      main snippet:

      def main():
          app = QtWidgets.QApplication([])
          window = QtWidgets.QWidget()
          window.setWindowTitle("kabantu")
          label = QtWidgets.QLabel(window)
          pixel = QtGui.QPixmap.fromImage(QtGui.QImage("kabantu.png"))
          label.setPixmap(pixel)
          label.setFixedSize(380, 136)
          label.setScaledContents(True)
          titleLabel = QtWidgets.QLabel(window)
          titleLabel.setText("kabantu 26.04 lts installer")
          titleLabel.setStyleSheet("font-size: 20px;")
          titleLabel.setAlignment(QtCore.Qt.AlignCenter)
          font = titleLabel.font()
          font.setBold(True)
          layout = QtWidgets.QVBoxLayout()
          layout.setAlignment(QtCore.Qt.AlignCenter)
          layout.addWidget(label)
          layout.addWidget(titleLabel)
          window.setWindowIcon(QtGui.QIcon("./kabantu.png"))  
          window.setFixedSize(400, 200)
          window.show()
          app.exec_()
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @zeankundev
      You add your widgets to a layout, but you don't seem to put the layout anywhere on the window?

      Z 1 Reply Last reply
      1
      • JonBJ JonB

        @zeankundev
        You add your widgets to a layout, but you don't seem to put the layout anywhere on the window?

        Z Offline
        Z Offline
        zeankundev
        wrote on last edited by
        #3

        @JonB Like how the py code should go?

        JonBJ 1 Reply Last reply
        0
        • Z zeankundev

          @JonB Like how the py code should go?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @zeankundev
          One of:

          window.setLayout(layout)
          

          or when constructing the layout:

          layout = QtWidgets.QVBoxLayout(window)
          

          On a quite separate matter: in two places you use "kabantu.png" and "./kabantu.png". Be careful: these are relative paths, your code relies on the current working directory being somewhere (same place as where your .py file is?) for these to work. I do not know that Python guarantees to set the working directory to where the script is when running it, I do not think it does. Consider using an absolute path, e.g. one constructed from determining where the .py file is at runtime?

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved