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. Expand (drop) text from TableView from button
Forum Updated to NodeBB v4.3 + New Features

Expand (drop) text from TableView from button

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 663 Views 1 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.
  • J Offline
    J Offline
    JacobNovitsky
    wrote on last edited by
    #1

    I have TableView for data presentation
    in one column I want to have button or ?? something like that to expand
    10 maximum of lines, each >= 10 characters
    probably QString\n or maybe QList if there is a proper way
    If there is no convenient and neat way I would open new QWindow, but its lousy option

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      Just you undestand you would want something like:

      +----------------------------------+---------+-----------------------------------------+
      |               Col1               |  Col2   |          Col3                           | 
      +----------------------------------+---------+-----------------------------------------+
      | Value 1                          | Value 2 | Lorem ipsum dolor sit amet        ...   |
      +----------------------------------+---------+-----------------------------------------+
      

      And when you press the ... in Col3 it becomes

      +----------------------------------+---------+-----------------------------------------+
      |               Col1               |  Col2   |          Col3                           | 
      +----------------------------------+---------+-----------------------------------------+
      | Value 1                          | Value 2 | Lorem ipsum dolor sit amet, consectetur |
      |                                  |         | adipiscing elit sed do eiusmod tempor   |
      |                                  |         | incididunt ut labore et dolore magna    |
      +----------------------------------+---------+-----------------------------------------+
      

      correct?

      "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 Offline
        J Offline
        JacobNovitsky
        wrote on last edited by
        #3

        Yes, right
        but it can be just pushbutton with no text
        +----------------------------------+---------+-----------------------------------------+
        | Col1 | Col2 | Col3 |
        +----------------------------------+---------+-----------------------------------------+
        | Value 1 | Value 2 | QPushbutton_ ... |
        +----------------------------------+---------+------------------------+----------------+

        btw, could you share function you draw this table
        neat :)

        1 Reply Last reply
        0
        • A Offline
          A Offline
          ankou29666
          wrote on last edited by
          #4

          It is possible, but in order to give you the proper advice, I want to properly understand your request.
          So if I understand it right, you want the text in that particular cell to be expanded or collapsed on click on that particular cell ?

          J 1 Reply Last reply
          0
          • A ankou29666

            It is possible, but in order to give you the proper advice, I want to properly understand your request.
            So if I understand it right, you want the text in that particular cell to be expanded or collapsed on click on that particular cell ?

            J Offline
            J Offline
            JacobNovitsky
            wrote on last edited by
            #5

            @ankou29666 right
            another approach, just place pushbutton/raidobutton/checkbutton
            if you can do both, its much appreciated :)

            1 Reply Last reply
            0
            • A Offline
              A Offline
              ankou29666
              wrote on last edited by ankou29666
              #6

              To the most simple, what I would have done is set the delegate as something like this

              Text
              {
                  text: hoverHandler.hovered ? sourceData.text : sourceData.text.slice(30)
              
                  HoverHandler { id: hoverHandler }
              }
              

              Of course in this case the collapse / expand is performed by hovering and not clicking.

              With a click I would simply go to a simple Text with a mouse area and a collapsed property

              Text
              {
                  property bool collapsed: true
              
                  text: collapsed ? sourceData.text.slice(30) : sourceData.text
                  MouseArea
                  {
                       anchors.fill: parent
                       onClicked: collapsed = !collapsed
                  }
              }
              

              Text and MouseArea seem to me a more suitable way to acheive this, but if you want a Button, Radio or Check, this would be basically similar to my second example. Yours to see.

              so of course in this approach you will have your text sliced after 30 chars, yours to see how long you want it to be. The result will likely be cut right in the middle of a word, and you might want to cut after a certain number of words rather than a certain number of chars.

              1 Reply Last reply
              1
              • A Offline
                A Offline
                ankou29666
                wrote on last edited by ankou29666
                #7

                If you want only one cell to be expanded at a time (that is automatically collapsing the currently expanded cell when selecting another one) on a click, the RadioDelegate might be an interesting option to consider. And customize it in order to make disapear the round button (I don't really know how to call it) if you ever find this to be relevant.
                And simply use the RadioDelegate's text property to display your text.

                1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

                  Good point, I forgot to ask if it's QtWidgets or QML.
                  In widgets it's not trivial as text elision is enforced always in the backend of Qt so you'd have to implement your own sizeHint which is a pain in the backside

                  "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
                  • JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @ankou29666 , @VRonin I would not assume the OP is asking about QML.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      ankou29666
                      wrote on last edited by
                      #10

                      The original post talks about TableView and not QTableView, which made me figure out QML.
                      However, a new QWindow ... QQuickWindow inherits QWindow while QWidget doesnt ...

                      1 Reply Last reply
                      1

                      • Login

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