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. ListWidget Text size fixed
Forum Updated to NodeBB v4.3 + New Features

ListWidget Text size fixed

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 5 Posters 3.6k 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.
  • A Offline
    A Offline
    amarism
    wrote on 21 Jun 2018, 05:40 last edited by amarism
    #1

    Hello everyone.
    I am able to insert text inside the listwidget but I am facing the problem that my text size exceeding the listwidget size. So, I want to fix the size of text equal to listwidget row size and extra text comes below the text.
    I am using this code for insert text:-
    QListWidgetItem* pItem = new QListWidgetItem(string);
    pItem->setForeground(Qt::white); // sets white text
    QT_ThumblistWidget->addItem(pItem);
    Also uploading the output image:-
    0_1529562501801_textsize.png

    For the text, slider curser come. I want to fix the size of text equal to the image

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Prince_0912
      wrote on 21 Jun 2018, 10:14 last edited by
      #2

      Hi @amarism ,
      These 2 link will help you.

      link 1 , link 2

      A 1 Reply Last reply 21 Jun 2018, 10:51
      0
      • P Prince_0912
        21 Jun 2018, 10:14

        Hi @amarism ,
        These 2 link will help you.

        link 1 , link 2

        A Offline
        A Offline
        amarism
        wrote on 21 Jun 2018, 10:51 last edited by amarism
        #3

        @Prince_0912 Both links are not useful for me. they all are discussing the font size and I am asking about the text size managing

        P 1 Reply Last reply 21 Jun 2018, 10:57
        0
        • A amarism
          21 Jun 2018, 10:51

          @Prince_0912 Both links are not useful for me. they all are discussing the font size and I am asking about the text size managing

          P Offline
          P Offline
          Prince_0912
          wrote on 21 Jun 2018, 10:57 last edited by
          #4

          @amarism ,
          You can try like this in your code,
          setSizeHint(QSize((listWidget->width()),((listWidget->height()))));

          J 1 Reply Last reply 21 Jun 2018, 11:11
          0
          • P Prince_0912
            21 Jun 2018, 10:57

            @amarism ,
            You can try like this in your code,
            setSizeHint(QSize((listWidget->width()),((listWidget->height()))));

            J Offline
            J Offline
            JonB
            wrote on 21 Jun 2018, 11:11 last edited by
            #5

            @Prince_0912
            I don't know whether your code does what the OP wants, nor what widget you are calling setSizeHint() on, but it won't be right to be using QListWidget::height() in particular, if anything it will need to be QListWidgetItem::height().

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Prince_0912
              wrote on 21 Jun 2018, 11:17 last edited by
              #6

              @JonB
              I'm refer from link.
              like in this way it can be solved

              J 1 Reply Last reply 21 Jun 2018, 11:32
              0
              • P Prince_0912
                21 Jun 2018, 11:17

                @JonB
                I'm refer from link.
                like in this way it can be solved

                J Offline
                J Offline
                JonB
                wrote on 21 Jun 2018, 11:32 last edited by
                #7

                @Prince_0912
                In that link the example is:

                QListWidgetItem->setSizeHint(QSize((listWidget->width()),(listWidget->height()/4)));
                

                which is quite different because it divides the list widget's height by 4 to fit 4 QListWidgetItems vertically. If the OP uses your suggestion, it won't come out anything like he is asking for. Up to you & him.

                A 1 Reply Last reply 21 Jun 2018, 11:35
                0
                • J JonB
                  21 Jun 2018, 11:32

                  @Prince_0912
                  In that link the example is:

                  QListWidgetItem->setSizeHint(QSize((listWidget->width()),(listWidget->height()/4)));
                  

                  which is quite different because it divides the list widget's height by 4 to fit 4 QListWidgetItems vertically. If the OP uses your suggestion, it won't come out anything like he is asking for. Up to you & him.

                  A Offline
                  A Offline
                  amarism
                  wrote on 21 Jun 2018, 11:35 last edited by amarism
                  #8

                  @JonB When I use this code it will convert the whole height into 4 part. But I need to just break the text whose extra than image and print just below the main original text.
                  For Example, my extra text size is this and I want to cut the red part text and print below the text.

                  0_1529581110212_textsize2.png

                  J 1 Reply Last reply 21 Jun 2018, 11:37
                  0
                  • A amarism
                    21 Jun 2018, 11:35

                    @JonB When I use this code it will convert the whole height into 4 part. But I need to just break the text whose extra than image and print just below the main original text.
                    For Example, my extra text size is this and I want to cut the red part text and print below the text.

                    0_1529581110212_textsize2.png

                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 21 Jun 2018, 11:37 last edited by
                    #9

                    @amarism If I undesrand you correctly you need ward wrapping. I#M not sure QListWidget supports it, maybe you can do it via styles?

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

                    1 Reply Last reply
                    1
                    • V Offline
                      V Offline
                      VRonin
                      wrote on 21 Jun 2018, 13:11 last edited by
                      #10

                      http://doc.qt.io/qt-5/qlistview.html#wordWrap-prop

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      J 1 Reply Last reply 21 Jun 2018, 13:21
                      1
                      • V VRonin
                        21 Jun 2018, 13:11

                        http://doc.qt.io/qt-5/qlistview.html#wordWrap-prop

                        J Offline
                        J Offline
                        JonB
                        wrote on 21 Jun 2018, 13:21 last edited by
                        #11

                        @VRonin
                        In that doc it states:

                        Please note that even if wrapping is enabled, the cell will not be expanded to make room for the text. It will print ellipsis for text that cannot be shown, according to the view's textElideMode.

                        I wonder whether it will expand vertically given that statement?

                        V A 2 Replies Last reply 21 Jun 2018, 13:23
                        0
                        • J JonB
                          21 Jun 2018, 13:21

                          @VRonin
                          In that doc it states:

                          Please note that even if wrapping is enabled, the cell will not be expanded to make room for the text. It will print ellipsis for text that cannot be shown, according to the view's textElideMode.

                          I wonder whether it will expand vertically given that statement?

                          V Offline
                          V Offline
                          VRonin
                          wrote on 21 Jun 2018, 13:23 last edited by
                          #12

                          @JonB said in ListWidget Text size fixed:

                          I wonder whether it will expand vertically given that statement?

                          Indeed it won't that's the job of the delegate's sizeHint method

                          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                          ~Napoleon Bonaparte

                          On a crusade to banish setIndexWidget() from the holy land of Qt

                          1 Reply Last reply
                          0
                          • J JonB
                            21 Jun 2018, 13:21

                            @VRonin
                            In that doc it states:

                            Please note that even if wrapping is enabled, the cell will not be expanded to make room for the text. It will print ellipsis for text that cannot be shown, according to the view's textElideMode.

                            I wonder whether it will expand vertically given that statement?

                            A Offline
                            A Offline
                            amarism
                            wrote on 21 Jun 2018, 13:34 last edited by
                            #13

                            @JonB Wrapping is work for me. Thank you

                            1 Reply Last reply
                            1

                            1/13

                            21 Jun 2018, 05:40

                            • Login

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