How to stop parent from autosizing when widgets are added in Qt5
I have a QToolBar inside a QDockWidget and I am dynamically populating the toolbar with QToolButton instances.
This dock widget is on the right hand of the screen with others on the left. It starts up with a reasonable size but when I add more tool buttons than there is space for, the dock widget will expand as much as possible. I'd rather it keep the original size and have the tool buttons end up in the overflow area of the toolbar.
I've tried setting a fixed size constraint on the parent layout but this just results in the dock growing or shrinking as tool buttons are added or removed.
Any ideas?
qt qt5 qdockwidget qtoolbar qtoolbutton
add a comment |
I have a QToolBar inside a QDockWidget and I am dynamically populating the toolbar with QToolButton instances.
This dock widget is on the right hand of the screen with others on the left. It starts up with a reasonable size but when I add more tool buttons than there is space for, the dock widget will expand as much as possible. I'd rather it keep the original size and have the tool buttons end up in the overflow area of the toolbar.
I've tried setting a fixed size constraint on the parent layout but this just results in the dock growing or shrinking as tool buttons are added or removed.
Any ideas?
qt qt5 qdockwidget qtoolbar qtoolbutton
add a comment |
I have a QToolBar inside a QDockWidget and I am dynamically populating the toolbar with QToolButton instances.
This dock widget is on the right hand of the screen with others on the left. It starts up with a reasonable size but when I add more tool buttons than there is space for, the dock widget will expand as much as possible. I'd rather it keep the original size and have the tool buttons end up in the overflow area of the toolbar.
I've tried setting a fixed size constraint on the parent layout but this just results in the dock growing or shrinking as tool buttons are added or removed.
Any ideas?
qt qt5 qdockwidget qtoolbar qtoolbutton
I have a QToolBar inside a QDockWidget and I am dynamically populating the toolbar with QToolButton instances.
This dock widget is on the right hand of the screen with others on the left. It starts up with a reasonable size but when I add more tool buttons than there is space for, the dock widget will expand as much as possible. I'd rather it keep the original size and have the tool buttons end up in the overflow area of the toolbar.
I've tried setting a fixed size constraint on the parent layout but this just results in the dock growing or shrinking as tool buttons are added or removed.
Any ideas?
qt qt5 qdockwidget qtoolbar qtoolbutton
qt qt5 qdockwidget qtoolbar qtoolbutton
asked Nov 15 '18 at 16:42
Alan SparkAlan Spark
3,94253874
3,94253874
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I tried to make a GUI like Alan Spark's.
Under my circumstance,It didn't happend.
It is not beyond my thought,
but I doubt that QMainWindow.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
is related,
because I didn't install special Options at all except for it.
I can't find out the other special doubtful Options.
On the other thing,on my Special Occasion,
I don't have only a QMainWindow
and its ToolBar()
This QMainWindow
is on the QScrollArea
and the layouted QStackedWidget
.
QScrollArea is resized to (10000,50000)
For example:
word_stackedWidget = QtGui.QStackedWidget()
word_sheetwidget = QtGui.QScrollArea()
word_sheetwidget.resize(10000,50000)
layout = QtGui.QVBoxLayout()
layout.addWidget(word_stackedWidget)
word_sheetwidget.setLayout(layout)
word = MyMainWindow()
word_stackedWidget.addWidget(word)
word_stackedWidget.setCurrentWidget(word)
dockwidget.setWidget(word_stackedWidget)
It is a little complicated,but I believe that the size of QDockWidget is subjective to the Contents.QScrollArea has a vast size , so it may be related with something.
Truely These were a tiny idea, I'm sorry! (but this is too much for comments.)
These attached Widgets (ScrollArea & StackedWidget) are very useful because you can look over all area of the Widgets and you can Change your favorite Widget without difficulty.
Probably, My answer will not help you.
Added
I investigated in QDockWidget
's composition.
It has two QAbstractButton
and two QLayout
objects.
And It has one QObject
and one QAction
objects.
I made sure that two QAbstractButton
are the floating-change button and the close-button.(because I try to setText()
for them,they were deleted on the surface.)
After that, the doubtful thing is QLayout.
I tried to get the QLayout
Children , but return None
.
So at the default, QDockWidget has no layout widgets in itself.
But I think QLayout
has a method for setSizeConstraint and has an great influence on QDockWidget.
Perhaps you can also view this point.
1.You get the QDockWidget's chidren() (from QObject method)
2.You stream it as sequence,and get the layout() object.
3.You try to make the layout set QLayoutSize.
4.You see the result.
For example, I tried to set setFixedSize
.
After that, I couldn't move the dockwidget and resize it.
I also Think it may be meaningful if you add new widget for this dockwidget.
So this will also not be good solution.But for the notice,I wanted to write this result.
Added
If you use setFixedSize,You can subclass the QDockWidget and overwrite subclass.
QLayout.SetFixedSize The main widget’s size is set to PySide.QtGui.QLayoutItem.sizeHint() ; it cannot be resized at all.
I saw you tried to change the widgetsize flag to fixedSize so it would do good probably.
Thanks, you've given me some ideas. The closest that I've got so far is to use QSizePolicy::Ignored as the horizontal size policy for the widget within my dock widget. This works as long as the dock widgets are not resized, or else they will return to the default size when my toolbar updates. I hope that I can work around this.
– Alan Spark
Nov 21 '18 at 16:41
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53324118%2fhow-to-stop-parent-from-autosizing-when-widgets-are-added-in-qt5%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I tried to make a GUI like Alan Spark's.
Under my circumstance,It didn't happend.
It is not beyond my thought,
but I doubt that QMainWindow.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
is related,
because I didn't install special Options at all except for it.
I can't find out the other special doubtful Options.
On the other thing,on my Special Occasion,
I don't have only a QMainWindow
and its ToolBar()
This QMainWindow
is on the QScrollArea
and the layouted QStackedWidget
.
QScrollArea is resized to (10000,50000)
For example:
word_stackedWidget = QtGui.QStackedWidget()
word_sheetwidget = QtGui.QScrollArea()
word_sheetwidget.resize(10000,50000)
layout = QtGui.QVBoxLayout()
layout.addWidget(word_stackedWidget)
word_sheetwidget.setLayout(layout)
word = MyMainWindow()
word_stackedWidget.addWidget(word)
word_stackedWidget.setCurrentWidget(word)
dockwidget.setWidget(word_stackedWidget)
It is a little complicated,but I believe that the size of QDockWidget is subjective to the Contents.QScrollArea has a vast size , so it may be related with something.
Truely These were a tiny idea, I'm sorry! (but this is too much for comments.)
These attached Widgets (ScrollArea & StackedWidget) are very useful because you can look over all area of the Widgets and you can Change your favorite Widget without difficulty.
Probably, My answer will not help you.
Added
I investigated in QDockWidget
's composition.
It has two QAbstractButton
and two QLayout
objects.
And It has one QObject
and one QAction
objects.
I made sure that two QAbstractButton
are the floating-change button and the close-button.(because I try to setText()
for them,they were deleted on the surface.)
After that, the doubtful thing is QLayout.
I tried to get the QLayout
Children , but return None
.
So at the default, QDockWidget has no layout widgets in itself.
But I think QLayout
has a method for setSizeConstraint and has an great influence on QDockWidget.
Perhaps you can also view this point.
1.You get the QDockWidget's chidren() (from QObject method)
2.You stream it as sequence,and get the layout() object.
3.You try to make the layout set QLayoutSize.
4.You see the result.
For example, I tried to set setFixedSize
.
After that, I couldn't move the dockwidget and resize it.
I also Think it may be meaningful if you add new widget for this dockwidget.
So this will also not be good solution.But for the notice,I wanted to write this result.
Added
If you use setFixedSize,You can subclass the QDockWidget and overwrite subclass.
QLayout.SetFixedSize The main widget’s size is set to PySide.QtGui.QLayoutItem.sizeHint() ; it cannot be resized at all.
I saw you tried to change the widgetsize flag to fixedSize so it would do good probably.
Thanks, you've given me some ideas. The closest that I've got so far is to use QSizePolicy::Ignored as the horizontal size policy for the widget within my dock widget. This works as long as the dock widgets are not resized, or else they will return to the default size when my toolbar updates. I hope that I can work around this.
– Alan Spark
Nov 21 '18 at 16:41
add a comment |
I tried to make a GUI like Alan Spark's.
Under my circumstance,It didn't happend.
It is not beyond my thought,
but I doubt that QMainWindow.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
is related,
because I didn't install special Options at all except for it.
I can't find out the other special doubtful Options.
On the other thing,on my Special Occasion,
I don't have only a QMainWindow
and its ToolBar()
This QMainWindow
is on the QScrollArea
and the layouted QStackedWidget
.
QScrollArea is resized to (10000,50000)
For example:
word_stackedWidget = QtGui.QStackedWidget()
word_sheetwidget = QtGui.QScrollArea()
word_sheetwidget.resize(10000,50000)
layout = QtGui.QVBoxLayout()
layout.addWidget(word_stackedWidget)
word_sheetwidget.setLayout(layout)
word = MyMainWindow()
word_stackedWidget.addWidget(word)
word_stackedWidget.setCurrentWidget(word)
dockwidget.setWidget(word_stackedWidget)
It is a little complicated,but I believe that the size of QDockWidget is subjective to the Contents.QScrollArea has a vast size , so it may be related with something.
Truely These were a tiny idea, I'm sorry! (but this is too much for comments.)
These attached Widgets (ScrollArea & StackedWidget) are very useful because you can look over all area of the Widgets and you can Change your favorite Widget without difficulty.
Probably, My answer will not help you.
Added
I investigated in QDockWidget
's composition.
It has two QAbstractButton
and two QLayout
objects.
And It has one QObject
and one QAction
objects.
I made sure that two QAbstractButton
are the floating-change button and the close-button.(because I try to setText()
for them,they were deleted on the surface.)
After that, the doubtful thing is QLayout.
I tried to get the QLayout
Children , but return None
.
So at the default, QDockWidget has no layout widgets in itself.
But I think QLayout
has a method for setSizeConstraint and has an great influence on QDockWidget.
Perhaps you can also view this point.
1.You get the QDockWidget's chidren() (from QObject method)
2.You stream it as sequence,and get the layout() object.
3.You try to make the layout set QLayoutSize.
4.You see the result.
For example, I tried to set setFixedSize
.
After that, I couldn't move the dockwidget and resize it.
I also Think it may be meaningful if you add new widget for this dockwidget.
So this will also not be good solution.But for the notice,I wanted to write this result.
Added
If you use setFixedSize,You can subclass the QDockWidget and overwrite subclass.
QLayout.SetFixedSize The main widget’s size is set to PySide.QtGui.QLayoutItem.sizeHint() ; it cannot be resized at all.
I saw you tried to change the widgetsize flag to fixedSize so it would do good probably.
Thanks, you've given me some ideas. The closest that I've got so far is to use QSizePolicy::Ignored as the horizontal size policy for the widget within my dock widget. This works as long as the dock widgets are not resized, or else they will return to the default size when my toolbar updates. I hope that I can work around this.
– Alan Spark
Nov 21 '18 at 16:41
add a comment |
I tried to make a GUI like Alan Spark's.
Under my circumstance,It didn't happend.
It is not beyond my thought,
but I doubt that QMainWindow.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
is related,
because I didn't install special Options at all except for it.
I can't find out the other special doubtful Options.
On the other thing,on my Special Occasion,
I don't have only a QMainWindow
and its ToolBar()
This QMainWindow
is on the QScrollArea
and the layouted QStackedWidget
.
QScrollArea is resized to (10000,50000)
For example:
word_stackedWidget = QtGui.QStackedWidget()
word_sheetwidget = QtGui.QScrollArea()
word_sheetwidget.resize(10000,50000)
layout = QtGui.QVBoxLayout()
layout.addWidget(word_stackedWidget)
word_sheetwidget.setLayout(layout)
word = MyMainWindow()
word_stackedWidget.addWidget(word)
word_stackedWidget.setCurrentWidget(word)
dockwidget.setWidget(word_stackedWidget)
It is a little complicated,but I believe that the size of QDockWidget is subjective to the Contents.QScrollArea has a vast size , so it may be related with something.
Truely These were a tiny idea, I'm sorry! (but this is too much for comments.)
These attached Widgets (ScrollArea & StackedWidget) are very useful because you can look over all area of the Widgets and you can Change your favorite Widget without difficulty.
Probably, My answer will not help you.
Added
I investigated in QDockWidget
's composition.
It has two QAbstractButton
and two QLayout
objects.
And It has one QObject
and one QAction
objects.
I made sure that two QAbstractButton
are the floating-change button and the close-button.(because I try to setText()
for them,they were deleted on the surface.)
After that, the doubtful thing is QLayout.
I tried to get the QLayout
Children , but return None
.
So at the default, QDockWidget has no layout widgets in itself.
But I think QLayout
has a method for setSizeConstraint and has an great influence on QDockWidget.
Perhaps you can also view this point.
1.You get the QDockWidget's chidren() (from QObject method)
2.You stream it as sequence,and get the layout() object.
3.You try to make the layout set QLayoutSize.
4.You see the result.
For example, I tried to set setFixedSize
.
After that, I couldn't move the dockwidget and resize it.
I also Think it may be meaningful if you add new widget for this dockwidget.
So this will also not be good solution.But for the notice,I wanted to write this result.
Added
If you use setFixedSize,You can subclass the QDockWidget and overwrite subclass.
QLayout.SetFixedSize The main widget’s size is set to PySide.QtGui.QLayoutItem.sizeHint() ; it cannot be resized at all.
I saw you tried to change the widgetsize flag to fixedSize so it would do good probably.
I tried to make a GUI like Alan Spark's.
Under my circumstance,It didn't happend.
It is not beyond my thought,
but I doubt that QMainWindow.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
is related,
because I didn't install special Options at all except for it.
I can't find out the other special doubtful Options.
On the other thing,on my Special Occasion,
I don't have only a QMainWindow
and its ToolBar()
This QMainWindow
is on the QScrollArea
and the layouted QStackedWidget
.
QScrollArea is resized to (10000,50000)
For example:
word_stackedWidget = QtGui.QStackedWidget()
word_sheetwidget = QtGui.QScrollArea()
word_sheetwidget.resize(10000,50000)
layout = QtGui.QVBoxLayout()
layout.addWidget(word_stackedWidget)
word_sheetwidget.setLayout(layout)
word = MyMainWindow()
word_stackedWidget.addWidget(word)
word_stackedWidget.setCurrentWidget(word)
dockwidget.setWidget(word_stackedWidget)
It is a little complicated,but I believe that the size of QDockWidget is subjective to the Contents.QScrollArea has a vast size , so it may be related with something.
Truely These were a tiny idea, I'm sorry! (but this is too much for comments.)
These attached Widgets (ScrollArea & StackedWidget) are very useful because you can look over all area of the Widgets and you can Change your favorite Widget without difficulty.
Probably, My answer will not help you.
Added
I investigated in QDockWidget
's composition.
It has two QAbstractButton
and two QLayout
objects.
And It has one QObject
and one QAction
objects.
I made sure that two QAbstractButton
are the floating-change button and the close-button.(because I try to setText()
for them,they were deleted on the surface.)
After that, the doubtful thing is QLayout.
I tried to get the QLayout
Children , but return None
.
So at the default, QDockWidget has no layout widgets in itself.
But I think QLayout
has a method for setSizeConstraint and has an great influence on QDockWidget.
Perhaps you can also view this point.
1.You get the QDockWidget's chidren() (from QObject method)
2.You stream it as sequence,and get the layout() object.
3.You try to make the layout set QLayoutSize.
4.You see the result.
For example, I tried to set setFixedSize
.
After that, I couldn't move the dockwidget and resize it.
I also Think it may be meaningful if you add new widget for this dockwidget.
So this will also not be good solution.But for the notice,I wanted to write this result.
Added
If you use setFixedSize,You can subclass the QDockWidget and overwrite subclass.
QLayout.SetFixedSize The main widget’s size is set to PySide.QtGui.QLayoutItem.sizeHint() ; it cannot be resized at all.
I saw you tried to change the widgetsize flag to fixedSize so it would do good probably.
edited Nov 21 '18 at 3:54
answered Nov 20 '18 at 12:36
user9402680user9402680
342210
342210
Thanks, you've given me some ideas. The closest that I've got so far is to use QSizePolicy::Ignored as the horizontal size policy for the widget within my dock widget. This works as long as the dock widgets are not resized, or else they will return to the default size when my toolbar updates. I hope that I can work around this.
– Alan Spark
Nov 21 '18 at 16:41
add a comment |
Thanks, you've given me some ideas. The closest that I've got so far is to use QSizePolicy::Ignored as the horizontal size policy for the widget within my dock widget. This works as long as the dock widgets are not resized, or else they will return to the default size when my toolbar updates. I hope that I can work around this.
– Alan Spark
Nov 21 '18 at 16:41
Thanks, you've given me some ideas. The closest that I've got so far is to use QSizePolicy::Ignored as the horizontal size policy for the widget within my dock widget. This works as long as the dock widgets are not resized, or else they will return to the default size when my toolbar updates. I hope that I can work around this.
– Alan Spark
Nov 21 '18 at 16:41
Thanks, you've given me some ideas. The closest that I've got so far is to use QSizePolicy::Ignored as the horizontal size policy for the widget within my dock widget. This works as long as the dock widgets are not resized, or else they will return to the default size when my toolbar updates. I hope that I can work around this.
– Alan Spark
Nov 21 '18 at 16:41
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53324118%2fhow-to-stop-parent-from-autosizing-when-widgets-are-added-in-qt5%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown