简体   繁体   English

在父QWidget区域之外显示子QWidget

[英]Show child QWidget out of parent QWidget area

I've got QListWidget as a child inside QPlainTextEdit for purposes of completion suggestions. 为了完成建议,我在QPlainTextEdit中将QListWidget作为孩子。

Suggestion list is displayed under cursor and when line is almost full, part of list widget is cropped by the border of text edit. 建议列表显示在光标下方,当行几乎满时,列表小部件的一部分被文本编辑的边框裁剪。 Is there any possibility to force child widget show out of parent widget region? 是否有可能迫使子窗口小部件显示出父窗口小部件区域?

An idea I have, is to make the text and list edit elements "siblings", ie add them to the same parent. 我的想法是使文本和列表编辑元素成为“同级”,即将它们添加到同一父级。 But this would require my event handling mechanism (as I suppose parent-child relation between those two elements). 但这需要我的事件处理机制(因为我假设这两个元素之间存在父子关系)。

I think there must be a way to achieve this, as I studied Katepart component and there is KateCompletionWidget (displays suggestions) that is direct child of KateView and when I run it (eg Kate text editor), the list is shown across text edit border. 我认为必须有一种方法可以实现这一点,因为我研究了Katepart组件,并且有KateCompletionWidget(显示建议)是KateView的直接子级,当我运行它(例如Kate文本编辑器)时,该列表显示在文本编辑边框之外。

There's no way for a child to paint outside of a parent's QWidget rect, unfortunately. 不幸的是,孩子没有办法在父母的QWidget矩形之外绘画。 Your sibling approach is a popular solution to this problem. 您的同级方法是解决此问题的常用方法。 Another approach is for the child to notify the parent of what it wants to draw, but this can be a bit more advanced because you have to re-implement paint events. 另一种方法是让孩子将要绘制的内容通知给父母,但这可能会更高级,因为您必须重新实现绘制事件。

Today I found a possibly viable way -- it's based on setWindowFlags(Qt::ToolTip) method of QListWidget element. 今天,我发现了一种可行的方法-它基于QListWidget元素的setWindowFlags(Qt::ToolTip)方法。 There's, however, some slight change in positioning and event handling. 但是,定位和事件处理方面有一些细微变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM