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 can QTextEdit send a message to its owner?
Qt 6.11 is out! See what's new in the release blog

How can QTextEdit send a message to its owner?

Scheduled Pinned Locked Moved Unsolved General and Desktop
20 Posts 5 Posters 1.6k 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.
  • SGaistS SGaist

    @clarify hi, what exactly do you want your view to react to ?
    Usually, the dataChanged signal of the model is used to notify the view that something has changed.

    C Offline
    C Offline
    clarify
    wrote on last edited by
    #8

    @SGaist
    I want to detect when the user has entered more characters
    into the QTextEdit than will fit in it horizontally.
    At that point I will make it taller.
    Since the QTextEdit is the source of truth about whether the text fits,
    I want it to emit that signal, rather than have the container
    reach into it (somehow) and determine whether the text fits.

    JonBJ 1 Reply Last reply
    0
    • C clarify

      @SGaist
      I want to detect when the user has entered more characters
      into the QTextEdit than will fit in it horizontally.
      At that point I will make it taller.
      Since the QTextEdit is the source of truth about whether the text fits,
      I want it to emit that signal, rather than have the container
      reach into it (somehow) and determine whether the text fits.

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

      @clarify
      That is quite correct, so have it emit the signal. Something still has to connect to the QTextEdit instance's signal.
      Or, depending on what you want to do, can you handle the behaviour you want inside a QTextEdit subclass maybe, without needing the outside world to be signalled?
      It might be that reimplementing QTextEdit::sizeHint() to expand on change is enough, don't know when that gets called though.

      I wonder if A QWidget like QTextEdit that wraps its height automatically to its contents? does just what you are looking for?
      Or there is https://github.com/cameel/auto-resizing-text-edit/blob/master/auto_resizing_text_edit/auto_resizing_text_edit.py ?

      C 1 Reply Last reply
      0
      • JonBJ JonB

        @clarify
        That is quite correct, so have it emit the signal. Something still has to connect to the QTextEdit instance's signal.
        Or, depending on what you want to do, can you handle the behaviour you want inside a QTextEdit subclass maybe, without needing the outside world to be signalled?
        It might be that reimplementing QTextEdit::sizeHint() to expand on change is enough, don't know when that gets called though.

        I wonder if A QWidget like QTextEdit that wraps its height automatically to its contents? does just what you are looking for?
        Or there is https://github.com/cameel/auto-resizing-text-edit/blob/master/auto_resizing_text_edit/auto_resizing_text_edit.py ?

        C Offline
        C Offline
        clarify
        wrote on last edited by clarify
        #10

        @JonB
        But where would I ideally make the call to connect?
        If I put it right before the emit, I'll be calling connect repeatedly.
        Also I am finding that windowHandle always returns NULL, no matter where I call it.
        But the slot is in the main window.

        JonBJ 1 Reply Last reply
        0
        • C clarify

          @JonB
          But where would I ideally make the call to connect?
          If I put it right before the emit, I'll be calling connect repeatedly.
          Also I am finding that windowHandle always returns NULL, no matter where I call it.
          But the slot is in the main window.

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

          @clarify
          If you need to connect a signal you do it once, from somewhere which can see (i.e. has variables for) both the signalling and slot objects. If the slot is in the main window you may need to it there. Does it have access to the QTextEdit? Whether the slot needs to be in the main window I cannot say. It doesn't feel like a main window responsibility to deal with resizing a text edit within some table.

          If you take the approach of having perhaps a subclassed QTextEdit handle the required resizing itself per the links, without involving the outside world, that might avoid problems.

          C 1 Reply Last reply
          0
          • JonBJ JonB

            @clarify
            If you need to connect a signal you do it once, from somewhere which can see (i.e. has variables for) both the signalling and slot objects. If the slot is in the main window you may need to it there. Does it have access to the QTextEdit? Whether the slot needs to be in the main window I cannot say. It doesn't feel like a main window responsibility to deal with resizing a text edit within some table.

            If you take the approach of having perhaps a subclassed QTextEdit handle the required resizing itself per the links, without involving the outside world, that might avoid problems.

            C Offline
            C Offline
            clarify
            wrote on last edited by
            #12

            @JonB said in How can QTextEdit send a message to its owner?:

            It doesn't feel like a main window responsibility to deal with resizing a text edit within some table.

            I agree about that, but there seems to be no way to configure the table to let the cell that's being edited cause the row to be grown vertically.

            JonBJ 1 Reply Last reply
            0
            • C clarify

              @JonB said in How can QTextEdit send a message to its owner?:

              It doesn't feel like a main window responsibility to deal with resizing a text edit within some table.

              I agree about that, but there seems to be no way to configure the table to let the cell that's being edited cause the row to be grown vertically.

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

              @clarify
              What "table"?
              Did you look at the code from the stackoverflow link? Did you try it?

              C 1 Reply Last reply
              0
              • JonBJ JonB

                @clarify
                What "table"?
                Did you look at the code from the stackoverflow link? Did you try it?

                C Offline
                C Offline
                clarify
                wrote on last edited by
                #14

                @JonB The QTextEdit is inside a table cell.
                There's no way to get a pointer to the QTextEdit from the window code.

                JonBJ 1 Reply Last reply
                0
                • C clarify

                  @JonB The QTextEdit is inside a table cell.
                  There's no way to get a pointer to the QTextEdit from the window code.

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

                  @clarify
                  Can you actually explain what you have, we don't know? You have mentioned a main window, a text edit, and a "table".

                  Do you mean you have perhaps a QGridLayout? Do you mean you have a QTableView/QTableWidget? Have you made that editable and you are talking about the editor it presents? Or maybe you have used setCellWidget()? It's a lot easier if you say than we have to guess.

                  And/or why would the stackoverflow approach require the outside world to be connected to a signal or need to access the text edit?

                  C 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @clarify
                    Can you actually explain what you have, we don't know? You have mentioned a main window, a text edit, and a "table".

                    Do you mean you have perhaps a QGridLayout? Do you mean you have a QTableView/QTableWidget? Have you made that editable and you are talking about the editor it presents? Or maybe you have used setCellWidget()? It's a lot easier if you say than we have to guess.

                    And/or why would the stackoverflow approach require the outside world to be connected to a signal or need to access the text edit?

                    C Offline
                    C Offline
                    clarify
                    wrote on last edited by clarify
                    #16

                    @JonB Did you read all of the discussion?

                    I have a table (QTableWidget) which contains editable cells. When the user types too much, the cell (or row) height does not resize, no matter how I configure things.

                    I don't know about setCellWidget. I was once told I have to create the QTextEdit inside a delegate so that is where it's created. It seemed like a terrible way to do things, but it was described as a Qt-specific approach.

                    JonBJ 1 Reply Last reply
                    0
                    • C clarify

                      @JonB Did you read all of the discussion?

                      I have a table (QTableWidget) which contains editable cells. When the user types too much, the cell (or row) height does not resize, no matter how I configure things.

                      I don't know about setCellWidget. I was once told I have to create the QTextEdit inside a delegate so that is where it's created. It seemed like a terrible way to do things, but it was described as a Qt-specific approach.

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

                      @clarify said in How can QTextEdit send a message to its owner?:

                      I was once told I have to create the QTextEdit inside a delegate

                      And that is indeed exactly what you should do. Create your own QStyledItemDelegate-derived class to use your own QTextEdit-derived class for createEditor() and implement as per the stackoverflow thread. QStyledItemDelete also has its own sizeHint(). Set the delegate on the table widget cell/row/column.

                      C 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @clarify said in How can QTextEdit send a message to its owner?:

                        I was once told I have to create the QTextEdit inside a delegate

                        And that is indeed exactly what you should do. Create your own QStyledItemDelegate-derived class to use your own QTextEdit-derived class for createEditor() and implement as per the stackoverflow thread. QStyledItemDelete also has its own sizeHint(). Set the delegate on the table widget cell/row/column.

                        C Offline
                        C Offline
                        clarify
                        wrote on last edited by
                        #18

                        @JonB But if I continue with that, how will I make the call to connect?
                        Inside the delegate routine createEditor, I won't have a pointer to the window.

                        JonBJ 1 Reply Last reply
                        0
                        • C clarify

                          @JonB But if I continue with that, how will I make the call to connect?
                          Inside the delegate routine createEditor, I won't have a pointer to the window.

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

                          @clarify
                          To what window, and why?
                          I have explained too many times. There is no need to connect the outside world/main window to the text edit to implement what you want. I have asked several times if you have looked at and tried the stackoverflow approach. Over to you now.

                          C 1 Reply Last reply
                          0
                          • JonBJ JonB

                            @clarify
                            To what window, and why?
                            I have explained too many times. There is no need to connect the outside world/main window to the text edit to implement what you want. I have asked several times if you have looked at and tried the stackoverflow approach. Over to you now.

                            C Offline
                            C Offline
                            clarify
                            wrote on last edited by
                            #20

                            @JonB
                            There has to be some piece of code somewhere that manages the table row heights.
                            The table itself is unable to handle that.
                            Therefore that code is in its parent, the window.
                            To me this is very simple. The table is unable to resize a row automatically when the editor in a cell needs to grow vertically.
                            The SO code was in Python and some of the methods it showed didn't apply to C++, for instance there is no setHeightMin method.

                            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