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 implment word wrap text feature for QPushbutton ?
Forum Update on Monday, May 27th 2025

How to implment word wrap text feature for QPushbutton ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 3.8k 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.
  • Q Offline
    Q Offline
    Qt embedded developer
    wrote on last edited by Qt embedded developer
    #1

    I am facing difficulty to set Translated text in QPushbutton. because other language consist long word so it get cuts in QPushbutton. Now i want to use SetWordWrap() feature of QLabel on My static QPushbutton.

    Can any body suggest me best way to fix this problem ?

    Is there any best way is there to deal with this situation ?

    jsulmJ 1 Reply Last reply
    0
    • Q Qt embedded developer

      I am facing difficulty to set Translated text in QPushbutton. because other language consist long word so it get cuts in QPushbutton. Now i want to use SetWordWrap() feature of QLabel on My static QPushbutton.

      Can any body suggest me best way to fix this problem ?

      Is there any best way is there to deal with this situation ?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Qt-embedded-developer said in How to implment word wrap text feature for QPushbutton ?:

      static QPushbutton

      A static push button?!
      I hope you don't really have a static push button (or any other QObject based static class instance).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      Q 1 Reply Last reply
      1
      • jsulmJ jsulm

        @Qt-embedded-developer said in How to implment word wrap text feature for QPushbutton ?:

        static QPushbutton

        A static push button?!
        I hope you don't really have a static push button (or any other QObject based static class instance).

        Q Offline
        Q Offline
        Qt embedded developer
        wrote on last edited by Qt embedded developer
        #3

        @jsulm Sorry if i misunderstood the push button selected from widget box as static. i am telling regarding button selected from QTCreator's Widgetbox.

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

          Hi,

          Do you mean its size does not change ?

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

          Q 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            Do you mean its size does not change ?

            Q Offline
            Q Offline
            Qt embedded developer
            wrote on last edited by
            #5

            @SGaist without size change i need to add text in push button

            Screenshot from 2021-08-02 23-27-42.png

            1 Reply Last reply
            0
            • C Offline
              C Offline
              ChrisW67
              wrote on last edited by
              #6

              Was that image a mock up? If it was not, then it seems the text is already wrapping but there is simply not enough vertical space for three lines and the widget has done the best it can.

              The only way you will fit more text in a fixed box is to shrink the font. I think you could do this in an override of paintEvent(). See if the text will fit in the box using the QPainter tools. If not, shrink the font and try again. There will need to be some limits to how small you go etc.

              Q 1 Reply Last reply
              0
              • C ChrisW67

                Was that image a mock up? If it was not, then it seems the text is already wrapping but there is simply not enough vertical space for three lines and the widget has done the best it can.

                The only way you will fit more text in a fixed box is to shrink the font. I think you could do this in an override of paintEvent(). See if the text will fit in the box using the QPainter tools. If not, shrink the font and try again. There will need to be some limits to how small you go etc.

                Q Offline
                Q Offline
                Qt embedded developer
                wrote on last edited by
                #7

                @ChrisW67 no its not image mockup. its text in pushbutton. i have put "\n" character between 2 words so word come to next line.

                shrinking font done the task.

                But How to wrap text in Pushbutton ? can anybody give example.

                JonBJ 1 Reply Last reply
                0
                • Q Qt embedded developer

                  @ChrisW67 no its not image mockup. its text in pushbutton. i have put "\n" character between 2 words so word come to next line.

                  shrinking font done the task.

                  But How to wrap text in Pushbutton ? can anybody give example.

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

                  @Qt-embedded-developer said in How to implment word wrap text feature for QPushbutton ?:

                  But How to wrap text in Pushbutton ? can anybody give example.

                  Did you try Googling for QPushButton wrap text? That's what I would do....

                  It seems you have 3 options:

                  • Put an explicit \n character into the text at the desired spot, as you say you have done.

                  • Create a QLabel and set its setWordWrap(true), then super-impose it onto the center of the QPushButton.

                  • Just do it with a sub-classed QLabel (no QPushButton) and handle the mousePressEvent to emit the clicked signal.

                  1 Reply Last reply
                  3

                  • Login

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