0

I have a QDialog which has a layout, in this layout there are multiple QWidgets. Now I have a button, if the user presses this button I want to display a "tooltip" which displays some more information. This "tooltip" has to contain a layout.

For this I wanted to use a QWidget with an absolute position. When I put together the code mentioned in this question the solution does not work for me. I have also tried to use the QtWidget.raise_() function but the QWidget is not being displayed.

I stripped down my code to the following example:

# creating content layout = QtWidgets.QVBoxLayout() for i in range(0, 10): layout.addWidget(QtWidgets.QLabel("line {} - bla bla bla bla bla bla".format(i))) widget = QtWidgets.QWidget() widget.setLayout(layout) # creating dialog and apply the layout dialog = QtWidgets.QDialog() dialog.setLayout(layout) # creating the absolute positioned widget absolute_layout = QtWidgets.QVBoxLayout() absolute_layout.addWidget(QtWidgets.QLabel("Absolute positioned QWidget")) absolute_layout.addWidget(QtWidgets.QLabel("With some widgets in itself")) absolute_layout.addWidget(QtWidgets.QLabel("With some widgets in itself")) absolute_layout.addWidget(QtWidgets.QLabel("With some widgets in itself")) absolute = QtWidgets.QWidget(dialog) absolute.setLayout(absolute_layout) # show the absolute widget and move it absolute.show() absolute.move(10, 10) absolute.raise_() dialog.show() 

The dialog is shown correctly with the content in the layout but the absolute is not being shown.

What am I doing wrong?

2
  • There is really no point in using widgets for such a trivial task as this. A tooltip can render html, so just use a <table> for laying out the text. Commented Jan 31, 2018 at 18:48
  • @ekhumoro yes, I know that. The code written above is obviously not my real code. As I wrote I need to use a QLayout object in this "tooltip", this layout contains some custom widgets. With using html I cannot achieve the result I want to have. Commented Feb 5, 2018 at 8:54

2 Answers 2

1

By using...

absolute = QtWidgets.QWidget(dialog) 

you have made absolute a child of dialog. Hence the geometry of absolute will always be governed to some extent by dialog. If you want to be able to specify the absolute geometry of a widget use...

absolute = QtWidgets.QWidget() 
Sign up to request clarification or add additional context in comments.

1 Comment

But don't I have to make the absolute a child of dialog? If I call the show() method of a QWidget which does not have a child it will be shown as a new window.
0

So with the help of @G.M. I found out that the solution is really easy:

absolute = QtWidgets.QWidget() absolute.setParent(dialog) 

I was expecting that the QWidget::QWidget(QWidget * parent = 0, Qt::WindowFlags f = 0) constructor is calling the QWidget::setParent(QWidget * parent) method internally (which is not true?).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.