How to add a pushbuttons on the top and bottom of the colorbar
Here is my sample peace of code.I am using gridlayout in my program to add my plot,slider and buttons.Here i needto arrange the up,down push buttons in top and bottom of the colorbar, but i didn't get exactly. when i am using self.glayout.addWidget(self.down,9,3,1,1)it was tacking the entire layout.can anyone please guide me.
self.up = QtGui.QPushButton(_("up"))
self.up.setMaximumWidth(40)
self.up.setLayoutDirection(QtCore.Qt.RightToLeft)
self.down = QtGui.QPushButton(_("down"))
self.down.setLayoutDirection(QtCore.Qt.RightToLeft)
self.down.setMaximumWidth(60)
self.newwidget = QtGui.QWidget()
self.glayout = QtGui.QGridLayout(self.newwidget)
self.canvas = MplCanvas()
self.nextBtn = QtGui.QPushButton(_("Next"))
self.previousBtn = QtGui.QPushButton(_("Previous"))
self.squareNum = QtGui.QLineEdit()
self.glayout.addWidget(self.canvas,0,0,10,10)
self.glayout.addWidget(self.up,1,4,1,1)
self.glayout.addWidget(self.down,9,4,1,1)
self.glayout.addWidget(self.sl,0,10,10,1)
self.glayout.addWidget(self.nextBtn,10,8,1,1)
self.glayout.addWidget(self.previousBtn,10,0,1,1)
self.glayout.addWidget(self.squareNum,10,4,1,1)
self.scrollArea.setWidget(self.newwidget)
my image:
excepted image:
python python-2.7 matplotlib pyqt pyqt4
add a comment |
Here is my sample peace of code.I am using gridlayout in my program to add my plot,slider and buttons.Here i needto arrange the up,down push buttons in top and bottom of the colorbar, but i didn't get exactly. when i am using self.glayout.addWidget(self.down,9,3,1,1)it was tacking the entire layout.can anyone please guide me.
self.up = QtGui.QPushButton(_("up"))
self.up.setMaximumWidth(40)
self.up.setLayoutDirection(QtCore.Qt.RightToLeft)
self.down = QtGui.QPushButton(_("down"))
self.down.setLayoutDirection(QtCore.Qt.RightToLeft)
self.down.setMaximumWidth(60)
self.newwidget = QtGui.QWidget()
self.glayout = QtGui.QGridLayout(self.newwidget)
self.canvas = MplCanvas()
self.nextBtn = QtGui.QPushButton(_("Next"))
self.previousBtn = QtGui.QPushButton(_("Previous"))
self.squareNum = QtGui.QLineEdit()
self.glayout.addWidget(self.canvas,0,0,10,10)
self.glayout.addWidget(self.up,1,4,1,1)
self.glayout.addWidget(self.down,9,4,1,1)
self.glayout.addWidget(self.sl,0,10,10,1)
self.glayout.addWidget(self.nextBtn,10,8,1,1)
self.glayout.addWidget(self.previousBtn,10,0,1,1)
self.glayout.addWidget(self.squareNum,10,4,1,1)
self.scrollArea.setWidget(self.newwidget)
my image:
excepted image:
python python-2.7 matplotlib pyqt pyqt4
please share a Minimal, Complete, and Verifiable example
– eyllanesc
Nov 23 '18 at 16:16
add a comment |
Here is my sample peace of code.I am using gridlayout in my program to add my plot,slider and buttons.Here i needto arrange the up,down push buttons in top and bottom of the colorbar, but i didn't get exactly. when i am using self.glayout.addWidget(self.down,9,3,1,1)it was tacking the entire layout.can anyone please guide me.
self.up = QtGui.QPushButton(_("up"))
self.up.setMaximumWidth(40)
self.up.setLayoutDirection(QtCore.Qt.RightToLeft)
self.down = QtGui.QPushButton(_("down"))
self.down.setLayoutDirection(QtCore.Qt.RightToLeft)
self.down.setMaximumWidth(60)
self.newwidget = QtGui.QWidget()
self.glayout = QtGui.QGridLayout(self.newwidget)
self.canvas = MplCanvas()
self.nextBtn = QtGui.QPushButton(_("Next"))
self.previousBtn = QtGui.QPushButton(_("Previous"))
self.squareNum = QtGui.QLineEdit()
self.glayout.addWidget(self.canvas,0,0,10,10)
self.glayout.addWidget(self.up,1,4,1,1)
self.glayout.addWidget(self.down,9,4,1,1)
self.glayout.addWidget(self.sl,0,10,10,1)
self.glayout.addWidget(self.nextBtn,10,8,1,1)
self.glayout.addWidget(self.previousBtn,10,0,1,1)
self.glayout.addWidget(self.squareNum,10,4,1,1)
self.scrollArea.setWidget(self.newwidget)
my image:
excepted image:
python python-2.7 matplotlib pyqt pyqt4
Here is my sample peace of code.I am using gridlayout in my program to add my plot,slider and buttons.Here i needto arrange the up,down push buttons in top and bottom of the colorbar, but i didn't get exactly. when i am using self.glayout.addWidget(self.down,9,3,1,1)it was tacking the entire layout.can anyone please guide me.
self.up = QtGui.QPushButton(_("up"))
self.up.setMaximumWidth(40)
self.up.setLayoutDirection(QtCore.Qt.RightToLeft)
self.down = QtGui.QPushButton(_("down"))
self.down.setLayoutDirection(QtCore.Qt.RightToLeft)
self.down.setMaximumWidth(60)
self.newwidget = QtGui.QWidget()
self.glayout = QtGui.QGridLayout(self.newwidget)
self.canvas = MplCanvas()
self.nextBtn = QtGui.QPushButton(_("Next"))
self.previousBtn = QtGui.QPushButton(_("Previous"))
self.squareNum = QtGui.QLineEdit()
self.glayout.addWidget(self.canvas,0,0,10,10)
self.glayout.addWidget(self.up,1,4,1,1)
self.glayout.addWidget(self.down,9,4,1,1)
self.glayout.addWidget(self.sl,0,10,10,1)
self.glayout.addWidget(self.nextBtn,10,8,1,1)
self.glayout.addWidget(self.previousBtn,10,0,1,1)
self.glayout.addWidget(self.squareNum,10,4,1,1)
self.scrollArea.setWidget(self.newwidget)
my image:
excepted image:
python python-2.7 matplotlib pyqt pyqt4
python python-2.7 matplotlib pyqt pyqt4
edited Nov 23 '18 at 16:17
eyllanesc
85.1k103563
85.1k103563
asked Nov 23 '18 at 8:23
raghavaraghava
697
697
please share a Minimal, Complete, and Verifiable example
– eyllanesc
Nov 23 '18 at 16:16
add a comment |
please share a Minimal, Complete, and Verifiable example
– eyllanesc
Nov 23 '18 at 16:16
please share a Minimal, Complete, and Verifiable example
– eyllanesc
Nov 23 '18 at 16:16
please share a Minimal, Complete, and Verifiable example
– eyllanesc
Nov 23 '18 at 16:16
add a comment |
1 Answer
1
active
oldest
votes
If your plot and color bar can be separated, I would recommend using a vertical layout (QVBoxLayout) for the color bar + up/down button portion of your plot. You would add the widgets to the vertical layout like so:
vlayout = QVBoxLayout()
vlayout.addWidget(up_button)
vlayout.addWidget(color_bar) # I don't know which widget is your color bar
vlayout.addWidget(down_button)
Then, add this layout to your grid layout next to the main plot:
glayout = QGridLayout()
glayout.addWidget(plot, 0, 0)
glayout.addLayout(vlayout, 0, 1)
If instead, the issue is that your plot and color bar are combined as one and cannot be separated, you might want to instead sandwich your plot between two horizontal layouts like so:
vlayout = QVBoxLayout() # This is the main layout that will hold everything
top = QHBoxLayout()
bottom = QHBoxLayout()
top.addStretch(10) # This will push the button to the far right
top.addWidget(up_button, 1)
bottom.addStretch(10) # This will push the button to the far right
bottom.addWidget(down_button, 1)
vlayout.addLayout(top)
vlayout.addWidget(plot)
vlayout.addLayout(bottom)
I find in general that grid layouts are difficult to work with and that usually, vertical and horizontal layouts can be combined together to produce a better result that allows the layout manager to perform its primary function.
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%2f53442960%2fhow-to-add-a-pushbuttons-on-the-top-and-bottom-of-the-colorbar%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
If your plot and color bar can be separated, I would recommend using a vertical layout (QVBoxLayout) for the color bar + up/down button portion of your plot. You would add the widgets to the vertical layout like so:
vlayout = QVBoxLayout()
vlayout.addWidget(up_button)
vlayout.addWidget(color_bar) # I don't know which widget is your color bar
vlayout.addWidget(down_button)
Then, add this layout to your grid layout next to the main plot:
glayout = QGridLayout()
glayout.addWidget(plot, 0, 0)
glayout.addLayout(vlayout, 0, 1)
If instead, the issue is that your plot and color bar are combined as one and cannot be separated, you might want to instead sandwich your plot between two horizontal layouts like so:
vlayout = QVBoxLayout() # This is the main layout that will hold everything
top = QHBoxLayout()
bottom = QHBoxLayout()
top.addStretch(10) # This will push the button to the far right
top.addWidget(up_button, 1)
bottom.addStretch(10) # This will push the button to the far right
bottom.addWidget(down_button, 1)
vlayout.addLayout(top)
vlayout.addWidget(plot)
vlayout.addLayout(bottom)
I find in general that grid layouts are difficult to work with and that usually, vertical and horizontal layouts can be combined together to produce a better result that allows the layout manager to perform its primary function.
add a comment |
If your plot and color bar can be separated, I would recommend using a vertical layout (QVBoxLayout) for the color bar + up/down button portion of your plot. You would add the widgets to the vertical layout like so:
vlayout = QVBoxLayout()
vlayout.addWidget(up_button)
vlayout.addWidget(color_bar) # I don't know which widget is your color bar
vlayout.addWidget(down_button)
Then, add this layout to your grid layout next to the main plot:
glayout = QGridLayout()
glayout.addWidget(plot, 0, 0)
glayout.addLayout(vlayout, 0, 1)
If instead, the issue is that your plot and color bar are combined as one and cannot be separated, you might want to instead sandwich your plot between two horizontal layouts like so:
vlayout = QVBoxLayout() # This is the main layout that will hold everything
top = QHBoxLayout()
bottom = QHBoxLayout()
top.addStretch(10) # This will push the button to the far right
top.addWidget(up_button, 1)
bottom.addStretch(10) # This will push the button to the far right
bottom.addWidget(down_button, 1)
vlayout.addLayout(top)
vlayout.addWidget(plot)
vlayout.addLayout(bottom)
I find in general that grid layouts are difficult to work with and that usually, vertical and horizontal layouts can be combined together to produce a better result that allows the layout manager to perform its primary function.
add a comment |
If your plot and color bar can be separated, I would recommend using a vertical layout (QVBoxLayout) for the color bar + up/down button portion of your plot. You would add the widgets to the vertical layout like so:
vlayout = QVBoxLayout()
vlayout.addWidget(up_button)
vlayout.addWidget(color_bar) # I don't know which widget is your color bar
vlayout.addWidget(down_button)
Then, add this layout to your grid layout next to the main plot:
glayout = QGridLayout()
glayout.addWidget(plot, 0, 0)
glayout.addLayout(vlayout, 0, 1)
If instead, the issue is that your plot and color bar are combined as one and cannot be separated, you might want to instead sandwich your plot between two horizontal layouts like so:
vlayout = QVBoxLayout() # This is the main layout that will hold everything
top = QHBoxLayout()
bottom = QHBoxLayout()
top.addStretch(10) # This will push the button to the far right
top.addWidget(up_button, 1)
bottom.addStretch(10) # This will push the button to the far right
bottom.addWidget(down_button, 1)
vlayout.addLayout(top)
vlayout.addWidget(plot)
vlayout.addLayout(bottom)
I find in general that grid layouts are difficult to work with and that usually, vertical and horizontal layouts can be combined together to produce a better result that allows the layout manager to perform its primary function.
If your plot and color bar can be separated, I would recommend using a vertical layout (QVBoxLayout) for the color bar + up/down button portion of your plot. You would add the widgets to the vertical layout like so:
vlayout = QVBoxLayout()
vlayout.addWidget(up_button)
vlayout.addWidget(color_bar) # I don't know which widget is your color bar
vlayout.addWidget(down_button)
Then, add this layout to your grid layout next to the main plot:
glayout = QGridLayout()
glayout.addWidget(plot, 0, 0)
glayout.addLayout(vlayout, 0, 1)
If instead, the issue is that your plot and color bar are combined as one and cannot be separated, you might want to instead sandwich your plot between two horizontal layouts like so:
vlayout = QVBoxLayout() # This is the main layout that will hold everything
top = QHBoxLayout()
bottom = QHBoxLayout()
top.addStretch(10) # This will push the button to the far right
top.addWidget(up_button, 1)
bottom.addStretch(10) # This will push the button to the far right
bottom.addWidget(down_button, 1)
vlayout.addLayout(top)
vlayout.addWidget(plot)
vlayout.addLayout(bottom)
I find in general that grid layouts are difficult to work with and that usually, vertical and horizontal layouts can be combined together to produce a better result that allows the layout manager to perform its primary function.
answered Dec 4 '18 at 13:39
Joshua B. KollatJoshua B. Kollat
12
12
add a comment |
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%2f53442960%2fhow-to-add-a-pushbuttons-on-the-top-and-bottom-of-the-colorbar%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
please share a Minimal, Complete, and Verifiable example
– eyllanesc
Nov 23 '18 at 16:16