Show child QWidget out of parent QWidget area - qt

I've got QListWidget as a child inside QPlainTextEdit for purposes of completion suggestions.
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", i. e. 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 (e. g. Kate text editor), the list is shown across text edit border.

There's no way for a child to paint outside of a parent's QWidget rect, unfortunately. 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. There's, however, some slight change in positioning and event handling.

Related

Qt overlay(drop-up) box

I am creating a Qt application where I need to display contents in an overlay box(Please refer to the attached image). The box needs to slide up from behind the bottom dock when a button is pressed and slide down by toggling the button. I tried with a QWidget but couldn't achieve what I wanted. Also I don't know how to list the elements in the overlay box. The elements are dynamic or changing.
The widgets stacking order is defined by their order in the QObject hierarchy tree. The first element is the bottom, and every next is on top of the previous. Children are on top of their parents, in widgets confined within their bounds, in QML free.
If you want that sliding element to appear on top of everything else, just put its parent on top of everything else.
After all it is on top of the bottom control bar, which is on top of the playlist, so you have it all worked out for you.
The same applies if you decide to do the wiser thing and use QML instead of QWidget. Animation and states are much easier there. Not to mention more specific designs.

Setting QWidget to maximize within parent in Qt Creator/Designer?

I have dragged and dropped a widget within a parent widget in the designer within qt creator.
It has an arbitrary fixed position rectangle within its parent.
I want to modify it such that it will conform to its parents dimensions. That is it should be "maximized" within its parent.
What button in the designer do I press to do this?
This is what layouts are for. See this for an explanation.
I'm not particularly familiar with Qt Designer, but the general process is to create a layout (QHBoxLayout would work for you) for the parent widget, and add the child widget to that layout.
Another thing to consider is that, in your case, you could simply set the child widget to be the central widget of the QMainWindow:
this->setCentralWidget(theMaximizedWidget);

drawForeground on QGraphicsRectItem

I need a way for a QGraphicsRectItem to draw on top of its children. I have a item that contains several children items. At a specific height I need to draw a line over the child items.
Is there a way to implement a drawForeground in a QGraphicsItems similar to the drawForeground in QGraphicsScene?
If at all possible I would prefer to not have to draw the line for each child item.
I'm not entirely sure what you are trying to do but I suspect you will encounter a great deal of grief trying to fight the framework by trying to make a part of the parent draw over its child items. Perhaps you can add a top level child that is over the other child items covering a limited area, and renders the same content as the parent and includes the special overlay lines you want?
It might also suit your purpose to draw right over the scene from the graphics view.

finding the top-level widget on a non-activewindow in qt

I'm trying to find the top-level widget on a non-active window. But I do not want to use QApplication::topLevelAt() method.
I have a main window and several child widget's of main window's central widget. Is it possible to distinguish whether one of the child widget is on top of other childs?
Sami
QObject::children() lists the children of a given object. For QWidgets, the children are drawn in order of the list, which means that you can get the top-most (last-drawn) child with the following code:
QWidget *topmost_p = qobject_cast<QWidget*>(parent_p->children().last());
Be aware that the above code may fail if the parent has no children.

Individual QTreeWidgetItem indentation

Is it possible to have individual indentation of items in a QTreeWidget?
In specific, I have have a column containing both text, icon and for some of them a CheckBox. The items without a CheckBox gets shifted to the left so the indentation of the icon and the text is not inline with the others. Could maybe be fixed with a hidden CheckBox if that is possible?
Maybe the use of Delegates will give you a nice and proper implementation. You'll have the opportunity to re-implement the paint() and sizeHint() methods, and therefore, choose the way your QTreeWidgetItem are being drawn...
More documentation here : http://doc.trolltech.com/4.6/model-view-delegate.html
An example : http://doc.trolltech.com/4.6/itemviews-pixelator.html
Hope it helps a bit !
You can try using the QWidget::setContentMargins() on the widget returned by QTreeWidget::itemWidget().

Resources