How to add a pushbuttons on the top and bottom of the colorbar












0















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:



enter image description here



excepted image:



enter image description here










share|improve this question

























  • please share a Minimal, Complete, and Verifiable example

    – eyllanesc
    Nov 23 '18 at 16:16
















0















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:



enter image description here



excepted image:



enter image description here










share|improve this question

























  • please share a Minimal, Complete, and Verifiable example

    – eyllanesc
    Nov 23 '18 at 16:16














0












0








0








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:



enter image description here



excepted image:



enter image description here










share|improve this question
















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:



enter image description here



excepted image:



enter image description here







python python-2.7 matplotlib pyqt pyqt4






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












1 Answer
1






active

oldest

votes


















0














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.






share|improve this answer
























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    0














    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.






    share|improve this answer




























      0














      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.






      share|improve this answer


























        0












        0








        0







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 4 '18 at 13:39









        Joshua B. KollatJoshua B. Kollat

        12




        12
































            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?