Navigation bar expansion package based on PyQt5 and PySide2.(x64 bit os only)
Project description
GNavbar is an expansion package based on PyQt5 (PySide2). It can be used to create navigation bars on the windows generated by PyQt5 (PySide2). It can save time for users to manually set the navigation bar. It also supports self-designed navigation bar styles to make the window more beautiful. At the same time, GNavbar also supports unlimited nesting!
This version is the first release of the GNavbar module, and the previous version is a beta version.
Supported Platforms
Operating system: Windows x64 bit >= 8.1 , Other OS have not been tested
Python: Python >= 3.10
Others: PyQt5 or PySide2 (Currently, other versions of Qt for Python are not supported)
Installation
GNavbar can be installed from PyPI
pip install GNavbar
If the download speed in your region is too slow, you can use the mirror station as follows
pip install -i [URL of the mirror station] GNavbar
Expected Updates (v1.0→v1.1)
1 . Navigation bar centering function will be added.
2 . The function of customized navigation bar will be improved.
Simple usage
This is a simple example of using GNavbar, but the final effect is very ugly. Because the code is really too simple.
import sys
#Several modules here are replaced by '*'.
try:
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
except ImportError:
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from GNavbar import *
class Demo(QFrame):
def __init__(self):
super(Demo,self).__init__()
self.resize(494, 300)
#Create a Navigation Bar.
self.n = GNavbar(self)
#Add items to the navigation bar and set the size of the items.
self.n.addNavbar(100,50)
#Set text for navigation bar items.
self.n.setNavbarText(i=0,text='First GNavbar')
#Set the page corresponding to the navigation bar item.
self.n.setPage(0,self.page1)
#Set the grid layout so that the navigation bar is rolled out to the entire window.
self.gridLayout = QGridLayout(self)
self.gridLayout.setObjectName(u"gridLayout")
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.addWidget(self.n, 0, 0, 0, 0)
QMetaObject.connectSlotsByName(self)
self.setWindowTitle("GNavbar DemoWindow")
def page1(self,frame):
#Specific contents of the corresponding page of the navigation bar.
self.pushButton = QPushButton(frame)
self.pushButton.setObjectName(u"pushButton")
self.pushButton.setGeometry(QRect(0, 0, 100, 100))
self.pushButton.setText("Hello GNavbar")
if __name__ == "__main__":
#run
app = QApplication(sys.argv)
demo = Demo()
demo.show()
sys.exit(app.exec())
The previous example is the simplest way to use it.
Add Style
We can add some “meat and blood” to make it look beautiful, as in the following example. The default navigation bar in GNavbar is the left navigation bar. If you don’t like the left navigation bar, you can change it to the right, top, or bottom navigation bar with the following code.
self.n.setLeft()
self.n.setRight()
self.n.setTop()
self.n.setBottom()
We can also set the StyleSheet for the navigation bar. These style sheets do not inherit to the page corresponding to the navigation bar item. They only work on the navigation bar.In this way, we can set the style on the navigation bar with confidence and boldness, without worrying about other content being affected by it.
self.n.setStyleSheet(u"background-color: rgb(40,40,150);")
If you don’t like setting the style sheet to achieve the background color, you can set the background color, the selected color and the foreground color by setting the theme color.
#Note: The colors here only support the form of ‘qRgb()’.
self.n.setColor(qRgb(40,40,150),qRgb(100,100,250),qRgb(255,255,255))
Next, we set the spacing between adjacent navigation bar items. The default value in GNavbar is no gap. It can make the navigation bar more beautiful.
#Set spacing to 10.
self.n.setSpacing(10)
If you want to set more fonts, there are two ways for you to choose. You can set the font of the entire navigation bar; You can also set the font of a navigation bar item.
#Set the font of navigation bar.
self.n.setFont(size=15,bold=True,font='Microsoft YaHei UI')
#Set the font of a navigation bar item,Set fonts when setting text.
self.n.setNavbarText(self,i=0,text='First GNavbar',size=15,bold=True,font='Microsoft YaHei UI')
Of course, there are more methods for style setting, which are listed below.
#Note:All 'i', 'index', 'width', 'height' and 'size' are integer.
#Set the horizontal and vertical distance between two adjacent items on the navigation bar.
self.n.setGrid(width,height)
#Set the size of navigation bar items.
self.n.setNavbarSize(i,width,height)
#Set horizontal alignment for all text on the navigation bar,The default is horizontal center alignment.
self.n.AutoTextCenter()
self.n.AutoTextLeft()
self.n.AutoTextRight()
#Set icon for navigation bar item.
self.n.setNavbarIcon(i,icon,size)
#Delete navigation bar Item.
self.n.deleteNavbar(i)
#Set the background color of navigation bar item,Color is limited to qRgb.
self.n.setNavbarColor(i,color)
#Set to automatically determine the size of the navigation bar according to the window size,where 'w' and 'h' are multiples of window width and height.
self.n.setAutoSize(w,h)
#Sets the fixed size of the navigation bar. This method has the opposite effect to setAutoSize().
self.n.setSize(width,height)
#Set the mode of the navigation bar to icon mode.
self.n.setIconMode()
#Set the mode of the navigation bar to list mode.
self.n.setListMode()
#Force navigation bar refresh
self.n.u()
#Switch the page corresponding to the navigation bar.
self.n.change(index)
#Set whether to open the navigation bar box border,only bool value.
self.n.box(tf)
#Set the content of the navigation bar item to synchronize to its page.
self.n.setFlowFrame(i)
#Delete Page Synchronization.
self.n.delFlow(i)
#Set custom navigation bar item.
self.n.setOwnNavbar(i,widget)
This is all the content of this version of GNavbar. How about it? Is it easy to use? Is it powerful? I believe you can use it to make beautiful window programs! Let’s work together!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters