Python Forum
Button creation on Widget
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Button creation on Widget
#1
Hi All,

I have created a QPushButtons on the top of the widget, but then I wanted to add those buttons on the left side of the widget.

any suggestion would be appreciated.

Regards,
Maiya
Reply
#2
Can you post your code?
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts


Reply
#3
Use a toolbar.
Then you can specify where the toolbar is (top, left, right, bottom).
You can also move the toolbar with the mouse.


from PyQt5.QtWidgets import (QMainWindow, QApplication, QVBoxLayout, QHBoxLayout, 
                             QWidget, QPushButton, QToolBar)
from PyQt5.QtCore import Qt


class mainWin(QMainWindow):
    def __init__(self, parent = None):
        super(mainWin, self).__init__(parent)
        self.setupUI()
        
    def setupUI(self):
        self.setGeometry(0, 0, 800, 600)
        central_widget = QWidget()
        vbox = QVBoxLayout()
        central_widget.setLayout(vbox)
        
        tbar = QToolBar("Test")
        btn = QPushButton("Open")
        btn.clicked.connect(self.btn_clicked)
        tbar.addWidget(btn)

        btn_save = QPushButton("Save")
        tbar.addWidget(btn_save)
        
        self.addToolBar(Qt.LeftToolBarArea, tbar)
        
        self.setCentralWidget(central_widget)
        
    def btn_clicked(self):
        print("Open button clicked")


if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    win = mainWin()
    win.setWindowTitle("Main Window")
    win.show()

    sys.exit(app.exec_())
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to simplify widget creation? flash77 6 2,297 Jul-21-2023, 08:03 PM
Last Post: deanhystad
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 6,065 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  [Tkinter] Button widget gets stuck from using tkinter.messagebox? Nwb 2 4,911 Jun-20-2018, 02:21 PM
Last Post: Nwb

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020