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 show the long text on a label that just show the latest part.
QtWS25 Last Chance

How to show the long text on a label that just show the latest part.

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 868 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.
  • MihanM Offline
    MihanM Offline
    Mihan
    wrote on last edited by
    #1

    e.g. a label's width is 100 (pixel) ,a text's width is 200 (pixel), i want the label just show last 100 pixel content of the text, the label's size policy is fixed. Now it just shows the first 100 pixel and also without ellipsis to remind it has other 100 pixel. So how to do that ,thank you.

    J.HilkJ 1 Reply Last reply
    0
    • MihanM Mihan

      e.g. a label's width is 100 (pixel) ,a text's width is 200 (pixel), i want the label just show last 100 pixel content of the text, the label's size policy is fixed. Now it just shows the first 100 pixel and also without ellipsis to remind it has other 100 pixel. So how to do that ,thank you.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      hi @Mihan

      take a look at this elided label example:

      https://doc.qt.io/qt-5/qtwidgets-widgets-elidedlabel-example.html


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      5
      • MihanM Offline
        MihanM Offline
        Mihan
        wrote on last edited by
        #3

        dose it means it also can elide the content like
        e.g.
        abcdefg -> ...efg
        not
        abcdefg -> abc...

        1 Reply Last reply
        0
        • Kent-DorfmanK Offline
          Kent-DorfmanK Offline
          Kent-Dorfman
          wrote on last edited by
          #4

          not something I've ever had to do so there is probably a better way...but, I would most likely write the text to a bitmap, clip the bitmap to the relevant window, and then display it in the widget.

          MihanM 1 Reply Last reply
          0
          • Kent-DorfmanK Kent-Dorfman

            not something I've ever had to do so there is probably a better way...but, I would most likely write the text to a bitmap, clip the bitmap to the relevant window, and then display it in the widget.

            MihanM Offline
            MihanM Offline
            Mihan
            wrote on last edited by
            #5

            @Kent-Dorfman also I have an idea that usedrawText() on a widget like you said, but i think it is cumbersome XD. So I want to get a better way to do that~

            Kent-DorfmanK 1 Reply Last reply
            0
            • MihanM Mihan

              @Kent-Dorfman also I have an idea that usedrawText() on a widget like you said, but i think it is cumbersome XD. So I want to get a better way to do that~

              Kent-DorfmanK Offline
              Kent-DorfmanK Offline
              Kent-Dorfman
              wrote on last edited by
              #6

              @Mihan
              I wouldn't be too concerned...unless you're in a really resource constrained system.

              MihanM 1 Reply Last reply
              0
              • Kent-DorfmanK Kent-Dorfman

                @Mihan
                I wouldn't be too concerned...unless you're in a really resource constrained system.

                MihanM Offline
                MihanM Offline
                Mihan
                wrote on last edited by Mihan
                #7

                @Kent-Dorfman Yep, running on ARM. BTW, could you tell me how to make a LineEdit's text cursor always is visible. I found something in source code ,

                if (QApplication::keypadNavigationEnabled()) {
                        if (e->type() == QEvent::EnterEditFocus) {
                            end(false);
                            d->setCursorVisible(true);
                            d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime());
                        } else if (e->type() == QEvent::LeaveEditFocus) {
                            d->setCursorVisible(false);
                            d->control->setCursorBlinkPeriod(0);
                            if (d->control->hasAcceptableInput() || d->control->fixup())
                                emit editingFinished();
                        }
                    }
                

                it's in QLineEdit's event(), so how can I use this setCursorVisible(bool) ?

                MihanM 1 Reply Last reply
                0
                • MihanM Mihan

                  @Kent-Dorfman Yep, running on ARM. BTW, could you tell me how to make a LineEdit's text cursor always is visible. I found something in source code ,

                  if (QApplication::keypadNavigationEnabled()) {
                          if (e->type() == QEvent::EnterEditFocus) {
                              end(false);
                              d->setCursorVisible(true);
                              d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime());
                          } else if (e->type() == QEvent::LeaveEditFocus) {
                              d->setCursorVisible(false);
                              d->control->setCursorBlinkPeriod(0);
                              if (d->control->hasAcceptableInput() || d->control->fixup())
                                  emit editingFinished();
                          }
                      }
                  

                  it's in QLineEdit's event(), so how can I use this setCursorVisible(bool) ?

                  MihanM Offline
                  MihanM Offline
                  Mihan
                  wrote on last edited by
                  #8
                  This post is deleted!
                  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