How can QTextEdit send a message to its owner?
-
@clarify
No, if you want to connect to aQTextEditsignal you need its instance to do theconnect().
Table cells are not relevant. Table cells cannot emit signals.
You might do the connect as theQTextEditis created/passed tosetCellWidget(), or you can find an existing one viacellWidget()calls if required.
Don't think of widgets sending messages to their owners, think of owners listening for any signals child widgets might send.@JonB The QTextEdit is created by a delegate of the table.
There's a method called createEditor in the delegate.
So I tried to call connect from the QTextEdit constructor, but
(updated:) I find that the object I want to send the message to,
which is the window, is NULL. -
@JonB The QTextEdit is created by a delegate of the table.
There's a method called createEditor in the delegate.
So I tried to call connect from the QTextEdit constructor, but
(updated:) I find that the object I want to send the message to,
which is the window, is NULL. -
@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.@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. -
@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.@clarify
That is quite correct, so have it emit the signal. Something still has to connect to theQTextEditinstance's signal.
Or, depending on what you want to do, can you handle the behaviour you want inside aQTextEditsubclass maybe, without needing the outside world to be signalled?
It might be that reimplementingQTextEdit::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 ? -
@clarify
That is quite correct, so have it emit the signal. Something still has to connect to theQTextEditinstance's signal.
Or, depending on what you want to do, can you handle the behaviour you want inside aQTextEditsubclass maybe, without needing the outside world to be signalled?
It might be that reimplementingQTextEdit::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 ?@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. -
@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.@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 theQTextEdit? 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
QTextEdithandle the required resizing itself per the links, without involving the outside world, that might avoid problems. -
@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 theQTextEdit? 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
QTextEdithandle the required resizing itself per the links, without involving the outside world, that might avoid problems.@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.
-
@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.
-
@JonB The QTextEdit is inside a table cell.
There's no way to get a pointer to the QTextEdit from the window code.@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 aQTableView/QTableWidget? Have you made that editable and you are talking about the editor it presents? Or maybe you have usedsetCellWidget()? 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?
-
@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 aQTableView/QTableWidget? Have you made that editable and you are talking about the editor it presents? Or maybe you have usedsetCellWidget()? 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?
@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.
-
@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.
@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 ownQTextEdit-derived class forcreateEditor()and implement as per the stackoverflow thread.QStyledItemDeletealso has its ownsizeHint(). Set the delegate on the table widget cell/row/column. -
@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 ownQTextEdit-derived class forcreateEditor()and implement as per the stackoverflow thread.QStyledItemDeletealso has its ownsizeHint(). Set the delegate on the table widget cell/row/column. -
@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.@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. -
@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.@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.