Issue
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?
Solution
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?).
Answered By - miile7
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.