Embedding custom QWidgets inside a QTextEdit



  • Hi, I'm working on the QtConsole and I've searched wide and high to a solution to this problem, and came up empty handed.
    This feature is of a really high importance to me, and I've wasted many hours on finding a solution to it, the closest I've got is QTextObject - but with no real-life examples and pretty shaky API I don't have an idea how to approach the implementation.

    Can anyone point me to the right direction? Is it even possible?
    Thanks!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    If you have a design like the Kate Editor in mind, the console is outside the editing widget which seems to be the best design.

    If not, what do you have in mind ?



  • @SGaist Hi SGaist, I'm working on the QtConsole, which is a "Qt-based console for working with Jupyter(IPython) kernels".
    It's emulating a console with a QTextEdit widget, which works really well - but I would like to embed custom QWidgets inside the console, which means inside the QTextEdit widget.


  • Lifetime Qt Champion

    What kind of widget would you like to embed ?



  • I left it open(QWidget) as I'm looking for a generic solution, but if an example can help - my first priority is a QTableView and QTreeView(think about visualizing the results of ls or os.listdir with a widget).


  • Lifetime Qt Champion

    For the table part, you should be able to do that directly with QTextEdit with help of html or the QTextDocument API.

    Otherwise you might have to use a layout + multiple QTextEdit/QWidget in a QScrollArea.

    Another alternative might be the Graphics View framework



  • Thanks @SGaist, I wasn't aware of QTextTable, which seems as a reasonable solution(but still we'll have to implement the sort and search which comes for free with the QTableView).

    About multiple QTextEdit/QWidgets in a QScrollArea, besides being a bit frustrating that it's the best solution, it's actually the closest I've seen, so thank you very much!


  • Lifetime Qt Champion

    One alternative might be to implement a QAbstractTextDocumentLayout


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.