Esempio n. 1
0
class TabWidget(QTabWidget):
       
    def __init__(self,parent = None):
        super(TabWidget,self).__init__(parent)
       
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setStyleSheet("QTabBar::tab {   "
                            "height: 40px; "
                            "background: rgb(214,214,214,0)   "
                            "}")
        self.closeButton = QPushButton(self)
        self.closeButton.setIcon(QIcon("images/close.png"))
        self.closeButton.setFlat(True)      
        self.mousePressed = False
               
        self.connect(self.closeButton, SIGNAL("clicked()"),self.closeWidget)
        
        self.setTabBar(TabBar(self))
       
    def closeBtn(self):
        return self.closeButton
        
    def closeWidget(self):
        self.emit(SIGNAL("closeWidget"))
        
    def setHasUnderLine(self,flag):
        self.tabBar().setHasUnderLine(flag)
       
    # 分割线
    def addSeperator(self):
        self.setTabEnabled(self.addTab(QWidget(self), "|"),False)
       
    def paintEvent(self,event):
        # 自定义标题,添加关闭按钮
        painter = QPainter(self)
        linearGradient = QLinearGradient(0, 0,0,self.tabBar().frameGeometry().height())
        linearGradient.setColorAt(0, QColor(60,150,255))
        linearGradient.setColorAt(0.05, QColor(6,88,200))
        linearGradient.setColorAt(1, QColor(80,150,255))
        painter.setBrush(QBrush(linearGradient))
        self.menuRect = QRect(0, 0, self.frameGeometry().width(), self.tabBar().height())
        painter.fillRect(self.menuRect, QBrush(linearGradient))
        self.closeButton.move(QPoint(self.geometry().width()-self.closeButton.frameGeometry().width(),
                              (self.tabBar().height()-self.closeButton.frameGeometry().height())/2))
Esempio n. 2
0
class ToolWidget(QDialog):
    def __init__(self,parent = None):
        super(ToolWidget,self).__init__(parent)
        
        #self.desktop = QDesktopWidget()
        self.desktop = QApplication.desktop()
#         self.setFixedSize(800,600)
        self.setWindowFlags(Qt.Dialog | Qt.FramelessWindowHint)
        
        self.move((self.desktop.width()-self.width())/2,(self.desktop.height()-self.height())/2)
        
        language = StoreInfoParser.instance().getLanguage()
        m_pTranslator = QTranslator()
        exePath = "./"
        if language == "chinese":
            QmName = "zh_CN.qm"
        else:
            QmName = "en_US.qm"
            
        if(m_pTranslator.load(QmName, exePath)):
            QCoreApplication.instance().installTranslator(m_pTranslator)
        
        self.tabWidget = TabWidget()
        #self.tabWidget.setFont(QFont("Times", 10, QFont.Bold))
        self.tabWidget.setFont(QFont("", 10, QFont.Bold))
        self.tabWidget.netService = NetWidget(self)
        
        self.tabWidget.hardService = HardWidget(self)
        #self.tabWidget.netService.textBrowser.setFixedWidth(self.geometry().width()*4/5)
        self.tabWidget.addTab(self.tabWidget.netService, self.tr("NetInfo"))
        self.tabWidget.addTab(self.tabWidget.hardService, self.tr("HardInfo"))
        
        layout = QVBoxLayout()
        layout.addWidget(self.tabWidget)
        layout.setMargin(0)
        self.setLayout(layout)
        
        self.tabWidget.netService.lineEdit.setFocus(True)
        
        self.closeButton = QPushButton(self)
        self.closeButton.setIcon(QIcon("images/close.png"))
        
        self.closeButton.setFlat(True)      
        self.closeButton.mousePressed = False
        
        self.connect(self.closeButton, SIGNAL("clicked()"),self.cancel)
        #self.connect(self.cancelButton, SIGNAL("clicked()"),self.cancel)
        
    def mouseMoveEvent(self,event):
        if self.closeButton.mousePressed:
            self.move(self.pos() + event.pos() - self.currentPos)   
        self.default = QString()
    def mousePressEvent(self,event):
        if event.buttons() == Qt.LeftButton:
            self.currentPos = event.pos()
            self.closeButton.mousePressed = True
   
    def mouseReleaseEvent(self,event):
        if event.buttons() == Qt.LeftButton:
            self.closeButton.mousePressed = False
            
    def cancel(self):
        self.close() 
        
    def paintEvent(self,event):
        self.closeButton.setFixedSize(30,30)
        self.closeButton.setIconSize(QSize(30,30))
        self.closeButton.move(QPoint(self.geometry().width()-self.closeButton.frameGeometry().width() - (self.tabWidget.tabBar().height()-self.closeButton.geometry().height())/2,(self.tabWidget.tabBar().height()-self.closeButton.geometry().height())/2))
Esempio n. 3
0
class TabWidget(QTabWidget):
       
    def __init__(self,parent = None):
        super(TabWidget,self).__init__(parent)
        
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setStyleSheet("QTabBar::tab {   "
                            "height: 40px; "
                            "width: 120px;"
                            "margin-top: 10px;"
                            "margin-left: 10px;"
                            "margin-bottom: 1px;"
                            "border-radius:1px;"   
                            "color: rgb(255, 255, 255);"         
                            "background: rgb(100,100,100,0)"
                            "}"
                            
                            "QTabBar::tab:selected{"
                            "background: rgb(255,255,255);"
                            "color: rgb(1, 1, 1);"
                            "}"
                            "QTabBar::tab:!selected:hover{"
                            "background: rgb(8,80,176);"
                            
                            "}"
                            )
       
        self.closeButton = QPushButton(self)
        self.closeButton.setIcon(QIcon("images/close.png"))
        self.closeButton.setFlat(True)      
#         self.closeButton.setStyleSheet("QPushButton::hover{background:rgb(50, 150, 255);};")
        
        self.mousePressed = False
               
        self.connect(self.closeButton, SIGNAL("clicked()"),self.closeWidget)
        
        self.setTabBar(TabBar(self))
        
    def closeBtn(self):
        return self.closeButton
        
    def closeWidget(self):
        self.emit(SIGNAL("closeWidget"))
        
    # 分割线
    def addSeperator(self):
        self.setTabEnabled(self.addTab(QWidget(self), "|"),False)
       
    def paintEvent(self,event):
        # 自定义标题,添加关闭按钮
        painter = QPainter(self)
        linearGradient = QLinearGradient(0, 0,0,self.tabBar().frameGeometry().height())
        linearGradient.setColorAt(0, QColor(60,150,255))
        linearGradient.setColorAt(0.1, QColor(6,88,200))
        linearGradient.setColorAt(1, QColor(80,150,255))
        painter.setBrush(QBrush(linearGradient))
        
        self.menuRect = QRect(0, 0, self.frameGeometry().width(), self.tabBar().height() - 1)#菜单矩形
        
        painter.fillRect(self.menuRect, QBrush(linearGradient))#填充
        
        painter2 = QPainter(self)#画
        brush2 = QBrush(QColor(242,242,242))#笔刷
        painter2.setBrush(brush2)#为画定义笔刷
        self.contenRect2 = QRect(0,self.tabBar().height(),self.frameGeometry().width(),self.frameGeometry().height())
        painter2.fillRect(self.contenRect2, brush2)
        
        self.closeButton.setFixedSize(30,30)
        self.closeButton.move(QPoint(self.geometry().width()-self.closeButton.frameGeometry().width() - 10,
                              (self.tabBar().height()-self.closeButton.frameGeometry().height())/2)) #关闭按钮的位置设定