Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to extends QLabel class for arranging text inside it

How to extends QLabel class for arranging text inside it

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 1.1k Views 2 Watching
  • 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.
  • T Offline
    T Offline
    Tab-Trader
    wrote on last edited by
    #1

    Good day!

    A little question:
    I have a few QFrames arranged inside QHBoxLayout. Each QFrame has one QHBoxLayout. Each QHBoxLayout contains a few QLabel items with some text. Inside QHBoxLayout every QLabel has their own stretch factor value. I'm setting up this using "layout->setStretchFactor();".

    I have a problem - if a QLabel contains a lot of text, Layout could not compact it according Stretch Factor which I set for this Label. How to extends QLabel class to arrange text to a few lines in situatuin of compressing QLabel width using QHBoxLayout?

    Thank you!

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      There is text elide examples in Qt examples directory of your installation. Which may help you.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      3
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        If you want it to break a long line to multiple lines,
        then you should make sure word wrap is enabled.
        If you mean, it should reduce font size, you need to subclass it and handle that yourself.

        1 Reply Last reply
        2
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Out of curiosity, why not use one of Qt's text oriented widgets like QTextEdit ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          T 1 Reply Last reply
          1
          • SGaistS SGaist

            Hi,

            Out of curiosity, why not use one of Qt's text oriented widgets like QTextEdit ?

            T Offline
            T Offline
            Tab-Trader
            wrote on last edited by
            #5

            @SGaist

            Thank you, QTextEdit works according my needs!

            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