def __setup_sub_window_dock(self, window: QWidget, config: dict, sub_window_data: SimpleNamespace): dock_name = config.get('DockName', '') dock_area = config.get('DockArea', Qt.NoDockWidgetArea) dock_show = config.get('DockShow', False) dock_float = config.get('DockFloat', False) dock_wnd = QDockWidget(dock_name, self) dock_wnd.setAllowedAreas( Qt.RightDockWidgetArea | Qt.LeftDockWidgetArea | Qt.TopDockWidgetArea | Qt.BottomDockWidgetArea) # With this setting, the dock widget cannot be closed # dock_wnd.setFeatures(QDockWidget.DockWidgetFloatable | QDockWidget.DockWidgetMovable) if dock_area != Qt.NoDockWidgetArea: if dock_area == Qt.AllDockWidgetAreas: self.addDockWidget(Qt.TopDockWidgetArea, dock_wnd) dock_wnd.setFloating(True) dock_wnd.move(QApplication.desktop().screen().rect().center() - self.rect().center()) else: self.addDockWidget(dock_area, dock_wnd) else: self.addDockWidget(Qt.TopDockWidgetArea, dock_wnd) dock_wnd.setFloating(True) dock_wnd.setAllowedAreas(Qt.NoDockWidgetArea) dock_wnd.move(QApplication.desktop().screen().rect().center() - self.rect().center()) dock_wnd.setWidget(window) if dock_float: dock_wnd.setFloating(True) # self.geometry().center() - dock_wnd.rect().center() # dock_wnd.move() if dock_show: dock_wnd.show() else: dock_wnd.hide() sub_window_data.dock_wnd = dock_wnd
def __setup_sub_window_dock(self, window: QWidget, config: dict, sub_window_data: SimpleNamespace): dock_name = config.get('DockName', '') dock_area = config.get('DockArea', Qt.NoDockWidgetArea) dock_show = config.get('DockShow', False) dock_float = config.get('DockFloat', False) dock_wnd = QDockWidget(dock_name, self) self.addDockWidget(dock_area, dock_wnd) dock_wnd.setWidget(window) if dock_float: dock_wnd.setFloating(True) dock_wnd.move(self.geometry().center() - dock_wnd.rect().center()) if dock_show: dock_wnd.show() sub_window_data.dock_wnd = dock_wnd
class DockDemo(QWidget): def __init__(self): QWidget.__init__(self) def init(self): self.setGeometry(300, 300, 300, 250) self.setStyleSheet('background-color:white;') self.btn1 = QPushButton('Button', self) self.dock1 = QDockWidget('My First Dock', self) self.dock1.move(20, 20) self.dock1.resize(200, 100) self.dock1.setWidget(self.btn1) self.dock1.setFloating(False) self.dock1.setFeatures(self.dock1.DockWidgetClosable | self.dock1.DockWidgetMovable) self.dock1.setFeatures(self.dock1.NoDockWidgetFeatures) self.show()
class Tab(QTabWidget): def __init__(self): super(Tab, self).__init__() self.initGUI() def initGUI(self): self.setGeometry(500, 300, 800, 650) self.setWindowTitle("CollegeBoard") self.tab1 = QWidget() self.tab2 = QWidget() self.tab3 = QWidget() self.tab4 = QWidget() self.tab5 = QWidget() self.addTab(self.tab1, "Personal information") self.addTab(self.tab2, "Choose a major") self.addTab(self.tab3, "Personal statement") self.addTab(self.tab4, "Register for a test") self.addTab(self.tab5, "Registration completed!") self.tab_1() self.tab_2() self.tab_3() self.tab_4() self.tab_5() self.setTabsClosable(True) self.tabCloseRequested.connect(self.closeTab) self.show() def closeTab(self, currentIndex): currentQWidget = self.widget(currentIndex) currentQWidget.deleteLater() self.removeTab(currentIndex) def tab_1(self): layout = QFormLayout() self.tab1.setLayout(layout) self.progressbar = QProgressBar(self) self.progressbar.setValue(0) layout.addRow(self.progressbar) self.btn1 = QPushButton('Next Page', self) self.btn1.clicked.connect(self.nextPage) self.btn1.move(650,600) self.txt1 = QLineEdit(self) self.txt1.setPlaceholderText("Cici") layout.addRow("First name", self.txt1) self.txt2 = QLineEdit(self) self.txt2.setPlaceholderText("Chen") layout.addRow("Last name", self.txt2) self.txt3 = QLineEdit(self) self.txt3.setPlaceholderText("") layout.addRow("Address", self.txt3) self.txt4 = QLineEdit(self) self.txt4.setPlaceholderText("") layout.addRow("Phone number", self.txt4) layout.addWidget(QLabel("Gender")) layout.addWidget(QCheckBox("Male")) layout.addWidget(QCheckBox("Female")) self.txt5 = QLineEdit(self) self.txt5.setPlaceholderText("") layout.addRow("Student ID", self.txt5) self.txt6 = QLineEdit(self) self.txt6.setPlaceholderText("mm/dd/yyyy") layout.addRow("Birthday", self.txt6) self.txt7 = QLineEdit(self) self.txt7.setPlaceholderText("Pacific American School") layout.addRow("High School", self.txt7) self.comboBox1 = QComboBox(self) self.comboBox1.addItem("January") self.comboBox1.addItem("February") self.comboBox1.addItem("March") self.comboBox1.addItem("April") self.comboBox1.addItem("May") self.comboBox1.addItem("June") self.comboBox1.addItem("July") self.comboBox1.addItem("August") self.comboBox1.addItem("September") self.comboBox1.addItem("October") self.comboBox1.addItem("November") self.comboBox1.addItem("December") layout.addRow("Graduation month", self.comboBox1) self.comboBox2 = QComboBox(self) self.comboBox2.addItem("2016") self.comboBox2.addItem("2017") self.comboBox2.addItem("2018") self.comboBox2.addItem("2019") self.comboBox2.addItem("2020") self.comboBox2.addItem("2021") self.comboBox2.addItem("2022") layout.addRow("Graduation year", self.comboBox2) self.btn2 = QPushButton('Change a photo', self) layout.addRow("", self.btn2) self.label1 = QLabel(self) layout.addRow(self.label1) self.label1.move(300, 60) self.label1.setPixmap(QPixmap('picture.jpg')) self.label1.resize(430, 60) def tab_2(self): layout = QFormLayout() self.tab2.setLayout(layout) self.btn1 = QPushButton('Next Page', self) self.btn1.clicked.connect(self.nextPage) self.btn1.move(650,600) self.progressbar = QProgressBar(self) self.progressbar.setValue(25) layout.addRow(self.progressbar) # -- add a checkbox self.check = QCheckBox('Biology', self) self.check.setTristate(True) # allowing tristate layout.addRow(self.check) self.check = QCheckBox('Chemistry', self) self.check.setTristate(True) # allowing tristate layout.addRow(self.check) self.check = QCheckBox('Computer science', self) self.check.setTristate(True) # allowing tristate layout.addRow(self.check) self.check = QCheckBox('Engineering', self) self.check.setTristate(True) # allowing tristate layout.addRow(self.check) self.check = QCheckBox('Arts & design', self) self.check.setTristate(True) # allowing tristate layout.addRow(self.check) self.check = QCheckBox('Literature', self) self.check.setTristate(True) # allowing tristate layout.addRow(self.check) self.check = QCheckBox('History', self) self.check.setTristate(True) # allowing tristate layout.addRow(self.check) self.check = QCheckBox('Language', self) self.check.setTristate(True) # allowing tristate layout.addRow(self.check) self.check = QCheckBox('Media', self) self.check.setTristate(True) # allowing tristate layout.addRow(self.check) self.check = QCheckBox('Philosophy', self) self.check.setTristate(True) # allowing tristate self.check.stateChanged.connect(self.dosth) layout.addRow(self.check) def dosth(self): state = self.check.checkState() if state == 0: self.setWindowTitle('You have deselected this major') elif state == 1: self.setWindowTitle('You are unsure of this major') elif state == 2: self.setWindowTitle('You have selected this major') def tab_3(self): layout = QFormLayout() self.tab3.setLayout(layout) self.btn1 = QPushButton('Next Page', self) self.btn1.clicked.connect(self.nextPage) self.btn1.move(650,600) self.progressbar = QProgressBar(self) self.progressbar.setValue(50) layout.addRow(self.progressbar) self.txt1 = QLineEdit('', self) self.txt2 = QLineEdit('', self) self.txt3 = QLineEdit('', self) self.txt4 = QLineEdit('', self) self.txt5 = QLineEdit('', self) self.dock1 = QDockWidget('Personal statement', self) self.dock1.move(20, 20) self.dock1.setWidget(self.txt1) self.dock1.setFloating(False) self.dock1.setFeatures(self.dock1.DockWidgetMovable) layout.addRow(self.dock1) layout.addRow('Please write a short statement about yourself.', self.txt1) layout.addRow(self.txt1) layout.addRow('What is your hobby?', self.txt2) layout.addRow(self.txt2) layout.addRow('What characteristics do you have that differs from others?', self.txt3) layout.addRow(self.txt3) layout.addRow('Which college do you want to go to and why?', self.txt4) layout.addRow(self.txt4) layout.addRow('Which after school activities did you attend in high school?', self.txt5) layout.addRow(self.txt5) def tab_4(self): layout = QFormLayout() self.tab4.setLayout(layout) self.btn1 = QPushButton('Next Page', self) self.btn1.clicked.connect(self.nextPage) self.btn1.move(650,600) self.progressbar = QProgressBar(self) self.progressbar.setValue(75) layout.addRow(self.progressbar) self.cal = QCalendarWidget(self) self.cal.setWindowTitle('Calendar') self.cal.setGridVisible(True) #one of the function self.cal.move(20, 100) self.cal.clicked[QDate].connect(self.showDate) self.label = QLabel(self) self.date = self.cal.selectedDate() #another function self.label.setText(self.date.toString()) self.label.move(100, 500) layout.addRow(self.cal) layout.addRow(self.label) # -- add a checkbox self.check1 = QCheckBox('SAT w/ essay', self) layout.addRow(self.check1) self.check2 = QCheckBox('Chinese w/ listening', self) layout.addRow(self.check2) self.check3 = QCheckBox('Physics', self) layout.addRow(self.check3) self.check4 = QCheckBox('Math I', self) layout.addRow(self.check4) self.check5 = QCheckBox('Math II', self) layout.addRow(self.check5) self.check6 = QCheckBox('Biology', self) layout.addRow(self.check6) self.check7 = QCheckBox('US History', self) layout.addRow(self.check7) self.check8 = QCheckBox('Literature', self) layout.addRow(self.check8) self.check9 = QCheckBox('Spanish', self) layout.addRow(self.check9) self.check10 = QCheckBox('French', self) layout.addRow(self.check10) # add a button self.btn1 = QPushButton('Reset', self) self.btn1.setToolTip('This button resets the checkbox!') self.btn1.resize(250, 90) self.btn1.move(100, 100) self.btn1.clicked.connect(self.reset) layout.addRow(self.btn1) def reset(self): self.check1.setChecked(False) self.check2.setChecked(False) self.check3.setChecked(False) self.check4.setChecked(False) self.check5.setChecked(False) self.check6.setChecked(False) self.check7.setChecked(False) self.check8.setChecked(False) self.check9.setChecked(False) self.check10.setChecked(False) def tab_5(self): layout = QFormLayout() self.tab5.setLayout(layout) self.label1 = QLabel(self) layout.addRow("Your registration have been successfully recorded. ☑️", self.label1) def showDate(self, date): self.label.setText(date.toString()) def nextPage(self): self.setCurrentIndex(self.currentIndex() + 1)
def init_ui(self): self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) ''' QText Edits ''' self.listing_gui = QLineEdit('', self) self.listing_gui.setFont(QFont('Arial', 12)) self.listing_gui.setPlaceholderText('Listing: ') self.listing_gui.resize(200, 30) self.listing_gui.move(0, 30) self.listing_gui.returnPressed.connect(self.get_listing) #width = listing_gui.frameGeometry().width() #height = listing_gui.frameGeometry().height() #print(width) #print(height) self.website_gui = QLineEdit('', self) self.website_gui.setFont(QFont('Arial', 12)) self.website_gui.setPlaceholderText('Website: ') self.website_gui.resize(200, 30) self.website_gui.move(0, 60) self.website_gui.returnPressed.connect(self.get_website) self.email_gui = QLineEdit('', self) self.email_gui.setFont(QFont('Arial', 12)) self.email_gui.setPlaceholderText('Email Address: ') self.email_gui.resize(200, 30) self.email_gui.move(0, 90) self.email_gui.returnPressed.connect(self.get_email) self.username_gui = QLineEdit('', self) self.username_gui.setFont(QFont('Arial', 12)) self.username_gui.setPlaceholderText('Username: '******'', self) self.password_gui.setFont(QFont('Arial', 12)) self.password_gui.setPlaceholderText('Password: '******''' End QText Edits ''' table = QTableWidget(self) table.setColumnCount(5) table.setRowCount(1) table.setHorizontalHeaderLabels('Listing;Website;Email Address;Username;Password'.split(";")) table.setItem(0, 0, QTableWidgetItem('Example Listing')) table.setItem(0, 1, QTableWidgetItem('https://example_website.com')) table.setItem(0, 2, QTableWidgetItem('*****@*****.**')) table.setItem(0, 3, QTableWidgetItem('ExampleUser66')) table.setItem(0, 4, QTableWidgetItem('ExAmPlEpassW0rd872@##@1')) table.resizeColumnsToContents() table.resizeRowsToContents() dock = QDockWidget('Table', self) dock.setWidget(table) dock.resize(800, 650 - 200) dock.move(0, 180) ''' Menu ''' mainMenu = self.menuBar() fileMenu = mainMenu.addMenu('File') exitButton = QAction('Exit', self) exitButton.setShortcut('Ctrl+Q') exitButton.setStatusTip('Exit application') exitButton.triggered.connect(self.close) printButton = QAction('Print File', self) printButton.setShortcut('Ctrl+P') printButton.setStatusTip('Print File') #printButton.triggered.connect() fileMenu.addAction(printButton) fileMenu.addAction(exitButton) editMenu = mainMenu.addMenu('Edit') viewMenu = mainMenu.addMenu('View') displayButton = QAction('Display All', self) displayButton.setShortcut('Ctrl+V') displayButton.setStatusTip('Display Entire File') #displayButton.triggered.connect() viewMenu.addAction(displayButton) searchMenu = mainMenu.addMenu('Search') searchStringButton = QAction('Search String', self) searchStringButton.setShortcut('Ctrl+S') searchStringButton.setStatusTip('Enter listing name in text box to search for that listing') #searchStringButton.triggered.connect() searchRowButton = QAction('Search Row', self) searchRowButton.setShortcut('Ctrl+R') searchRowButton.setStatusTip('Search a specific row') #searchRowButton.triggered.connect() searchColumnButton = QAction('Search Column', self) searchColumnButton.setShortcut('Ctrl+Y') searchColumnButton.setStatusTip('Enter the specific column you wish to search') #searchColumnButton.triggered.connect() searchMenu.addAction(searchStringButton) searchMenu.addAction(searchRowButton) searchMenu.addAction(searchColumnButton) toolsMenu = mainMenu.addMenu('Tools') helpMenu = mainMenu.addMenu('Help') ''' End Menu ''' self.show()
class MainWindow(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): maxWidth = QDesktopWidget().availableGeometry().width() maxHeight = QDesktopWidget().availableGeometry().height() workSpace = QWidget(self) #### MainWindow Configuration self.setWindowTitle("Application") self.setWindowIcon(QIcon("icon.png")) self.tray_icon = QSystemTrayIcon(QIcon("icon.png")) self.tray_icon.show() #### Tray MENU ################# trayIconMenu = QMenu(self) trayIconMenu.setTitle("Main menu") trayIconMenu.addAction("Show Main Window", self.showMainWindow) trayIconMenu.addAction("Switch chat", self.toggleDockWidget) trayIconMenu.addSeparator() trayIconMenu.addAction("Quit", self.close) self.tray_icon.setContextMenu(trayIconMenu) ###################################### #### MENUBAR description: ################# mainmenu = self.menuBar() file = mainmenu.addMenu("File") file.addAction("isFloating", self.floatingInfo) file.addAction("Toggle Chat", self.toggleDockWidget) file.addAction("Close", self.close) ###################### self.dockWidget = QDockWidget("Messenger", self) self.dockWidget.setFloating(True) self.dockWidget.setVisible(True) self.dockWidget.setMinimumSize(300, 460) self.dockWidget.setMaximumSize(maxWidth / 2, maxHeight) self.dockWidget.setBaseSize(maxWidth / 2, maxHeight) self.dockWidget.resize(maxWidth / 4, maxHeight / 1.5) self.dockWidget.setFeatures(QDockWidget.NoDockWidgetFeatures) self.dockWidget.setVisible(False) #### TODO:" set dockWidget widgets" ################ messengerWidget = QWidget() masterVertical = QVBoxLayout() messengerWidget.setLayout(masterVertical) slaveHorizont = QHBoxLayout() subSlaveVertical = QVBoxLayout() msgSpace = QListView() textEdit = QTextEdit() sendBtn = QPushButton("Send") masterVertical.addWidget(msgSpace) masterVertical.addLayout(slaveHorizont) slaveHorizont.addWidget(textEdit) slaveHorizont.addLayout(subSlaveVertical) subSlaveVertical.addWidget(sendBtn) # self.dockWidget.setLayout(QVBoxLayout()) # print(self.dockWidget.setLayout(QVBoxLayout())) ############################################################ # self.statusBar() toggleDockWidgetBtn = QPushButton("Show geomerty", workSpace) toggleDockWidgetBtn.move(10, 40) toggleDockWidgetBtn.clicked.connect(self.showGeometry) #### TEST BUTONS #### hideBtn = QPushButton("hide main", workSpace) hideBtn.move(10, 70) hideBtn.clicked.connect(self.hideMainWindow) ####################################################### self.setGeometry(300, 300, 300, 500) self.dockWidget.resize(333, 1000) self.setCentralWidget(workSpace) self.addDockWidget(Qt.RightDockWidgetArea, self.dockWidget) def toggleDockWidget(self): flag = False if self.dockWidget.isVisible() else True text = "Messenger status was changed to {}".format( "visible" if flag else "hide") self.dockWidget.setVisible(flag) # self.dockWidget.setGeometry(650, 300, 200, 500) #### SET DOCKWINDOW GEAMETRY AND POSITION qtRect = self.dockWidget.frameGeometry() rightPoint = QDesktopWidget().availableGeometry().bottomRight() #### FOR LINUX POSITION ############################### # qtRect.moveBottomRight(rightPoint) # self.dockWidget.move(qtRect.bottomRight()) #### FOR WINDOWS POSITION ############################# qtRect.moveBottomRight(rightPoint) self.dockWidget.move(qtRect.topLeft()) ############################################################## self.statusBar().showMessage(text, 500) #### test functionality def showGeometry(self): availGeometry = QDesktopWidget().availableGeometry() self.statusBar().showMessage("Available geometry.") print("Available geometry: ", availGeometry) print("Right point: ", QDesktopWidget().availableGeometry().bottomRight()) print("DockWidget frame bottomRight: ", self.dockWidget.frameGeometry().bottomRight()) print("DockWidget frame topLeft: ", self.dockWidget.frameGeometry().topLeft()) print("\n" + "|---|" * 15 + "\n") def hideMainWindow(self): self.hide() def showMainWindow(self): self.show() def floatingInfo(self): flag = False if self.dockWidget.isFloating() else True print("dockWidget status is: ", flag) self.dockWidget.setFloating(flag)