当前位置: 首页 > news >正文

复制网站源码推广网

复制网站源码,推广网,工作证明范本,兰州做it网站运营的怎么样无法通过QSS设置这些属性.要将样式更改为每个选项卡,我们必须创建一个自定义QTabBar并覆盖其paintEvent方法,以便能够更改我们使用QStyleOptionTab类的每个选项卡的样式,但是要更改QTabWidget选项卡,我们需要使用setTabBar方法但是这样是私有的,所以你需要创建一个自定义QTabWi…

无法通过QSS设置这些属性.要将样式更改为每个选项卡,我们必须创建一个自定义QTabBar并覆盖其paintEvent方法,以便能够更改我们使用QStyleOptionTab类的每个选项卡的样式,但是要更改QTabWidget选项卡,我们需要使用setTabBar方法但是这样是私有的,所以你需要创建一个自定义QTabWidget,如下所示:

tabwidget.h

#ifndef TABWIDGET_H

#define TABWIDGET_H

#include

#include

#include

class TabBar: public QTabBar

{

public:

TabBar(const QHash &colors, QWidget *parent=0):QTabBar(parent){

mColors = colors;

}

protected:

void paintEvent(QPaintEvent */*event*/){

QStylePainter painter(this);

QStyleOptionTab opt;

for(int i = 0;i < count();i++)

{

initStyleOption(&opt,i);

if(mColors.contains(opt.text)){

opt.palette.setColor(QPalette::Button, mColors[opt.text]);

}

painter.drawControl(QStyle::CE_TabBarTabShape, opt);

painter.drawControl(QStyle::CE_TabBarTabLabel,opt);

}

}

private:

QHash mColors;

};

class TabWidget : public QTabWidget

{

public:

TabWidget(QWidget *parent=0):QTabWidget(parent){

// text - color

QHash dict;

dict["All"] = QColor("yellow");

dict["purchase"] = QColor("#87ceeb");

dict["POS Sales"] = QColor("#90EE90");

dict["Cash Sales"] = QColor("pink");

dict["invoice"] = QColor("#800080");

setTabBar(new TabBar(dict));

}

};

#endif // TABWIDGET_H

要在Qt Designer的QTabWidget中使用它,我们应该提升它,我们右键单击tabwidget并选择菜单Promoted Widgets,在我的例子中,前面的代码是在tabwidget.h文件中创建的,所以这将是头文件和在Promoted Class Name的情况下,我们使用TabWidget,之后我们按下Add and Promote按钮获取下图中显示的内容:

最终结果如下图所示:

完整示例可在以下link中找到

Python:

from PyQt5 import QtGui, QtWidgets

class TabBar(QtWidgets.QTabBar):

def __init__(self, colors, parent=None):

super(TabBar, self).__init__(parent)

self.mColors = colors

def paintEvent(self, event):

painter = QtWidgets.QStylePainter(self)

opt = QtWidgets.QStyleOptionTab()

for i in range(self.count()):

self.initStyleOption(opt, i)

if opt.text in self.mColors:

opt.palette.setColor(

QtGui.QPalette.Button, self.mColors[opt.text]

)

painter.drawControl(QtWidgets.QStyle.CE_TabBarTabShape, opt)

painter.drawControl(QtWidgets.QStyle.CE_TabBarTabLabel, opt)

class TabWidget(QtWidgets.QTabWidget):

def __init__(self, parent=None):

super(TabWidget, self).__init__(parent)

d = {

"All": QtGui.QColor("yellow"),

"purchase": QtGui.QColor("#87ceeb"),

"POS Sales": QtGui.QColor("#90EE90"),

"Cash Sales": QtGui.QColor("pink"),

"invoice": QtGui.QColor("#800080"),

}

self.setTabBar(TabBar(d))

self.addTab(QtWidgets.QLabel(), "All")

self.addTab(QtWidgets.QLabel(), "purchase")

self.addTab(QtWidgets.QLabel(), "POS Sales")

self.addTab(QtWidgets.QLabel(), "Cash Sales")

self.addTab(QtWidgets.QLabel(), "invoice")

if __name__ == "__main__":

import sys

app = QtWidgets.QApplication(sys.argv)

app.setStyle("fusion")

w = TabWidget()

w.show()

sys.exit(app.exec_())

http://www.hrbkazy.com/news/18736.html

相关文章:

  • 邢台在百度上做个网站jsurl中文转码
  • 网络营销运营方案seo学习网站
  • 无极网站赌博涉案多少人被抓本地广告推广平台哪个好
  • 北京做网站建设公司哪家好郑州百度快照优化
  • 西安行业网站培训课程
  • 网站建设与管理试卷 判断题关键词排名怎么查
  • 做网站还是移动开发太原网络推广价格
  • 网站如何不需要备案网页设计制作
  • 广州网站建设定制株洲网站设计
  • 前后端分离实现网站开发郑州网络推广公司
  • 在网站后台管理系统里产品说明怎么添加图片百度一下 官方网
  • 网站建设方案书格式百度收录快的发帖平台
  • 网站 权限网络平台推广具体是怎么推广
  • 安全可信网站seo怎么优化网站排名
  • wordpress 参数 传递迈步者seo
  • 网站建设 山西新手如何学seo
  • 有专门做检验的视频网站吗比较好的品牌策划公司有哪些
  • 版面设计图大全seo怎么优化关键词排名培训
  • 网站共享备案快速网站推广公司
  • 微信官网网站模板下载不了长沙网络推广平台
  • 网站建设后如何放在网上中国互联网公司排名
  • 网络营销logoseo顾问收费
  • 东莞做网站怎么样5118和百度指数
  • 鲜花网站建设规划爱站网怎么使用
  • 阿里云服务器建立网站吗seo优化销售话术
  • wordpress python优化大师优化项目有哪些
  • 2015选择做导航网站互联网行业都有哪些工作
  • 深圳建筑工务署官网seo关键词智能排名
  • 帮朋友做网站 知乎基本seo技术在线咨询
  • 在电脑上做苗木网站河北高端网站建设