Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved How to implment word wrap text feature for QPushbutton ?

    General and Desktop
    5
    8
    740
    Loading More Posts
    • 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
      Qt embedded developer last edited by 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 ?

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @Qt embedded developer last edited by

        @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 Reply Quote 1
        • Q
          Qt embedded developer @jsulm last edited by Qt embedded developer

          @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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • Q
              Qt embedded developer @SGaist last edited by

              @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 Reply Quote 0
              • C
                ChrisW67 last edited by

                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 Reply Quote 0
                • Q
                  Qt embedded developer @ChrisW67 last edited by

                  @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.

                  JonB 1 Reply Last reply Reply Quote 0
                  • JonB
                    JonB @Qt embedded developer last edited by

                    @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 Reply Quote 3
                    • First post
                      Last post