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

国内外公司网站差异北京网站设计公司

国内外公司网站差异,北京网站设计公司,做女装的网站,多少钱算赌博本文主要介绍了qt普通菜单样式、带选中样式、带子菜单样式、超过一屏幕菜单样式、自定义带有滚动条的菜单样式, 先上图如下: 1.普通菜单样式 代码: m_pmenu new QMenu(this);m_pmenu->setObjectName("quoteListMenu"); qss文…

本文主要介绍了qt普通菜单样式、带选中样式、带子菜单样式、超过一屏幕菜单样式、自定义带有滚动条的菜单样式,

先上图如下:

1.普通菜单样式

代码:

    m_pmenu = new QMenu(this);m_pmenu->setObjectName("quoteListMenu");

qss文件:

QMenu {background-color: #3b3c49;margin:0px;padding:0px;
}QMenu::indicator {width: 31px;height:30px;background-color: #3b3c49;margin: 2px
}QMenu::indicator:selected {background-color: #144675;margin: 2px
}QMenu::indicator:disabled {background-color: #414141;margin: 2px
}QMenu::item {color: #ffffff;height:24px;font:normal 14px;margin:0px;padding-left:12px;padding-right:41px;
}QMenu::item:selected {color: #ffffff;background-color:#545563;
}QMenu::item:disabled {
color: #707070;
background-color: #414141;
}QMenu::indicator:checked {image:url(:/pic/tick.png);
}/********/
QMenu#quoteListMenu
{background: #3b3c49;margin-top: 8px;margin-bottom: 8px;padding: 0px;
}QMenu#quoteListMenu::item
{color: #ffffff;height: 24px;font-size: 14px;padding-left:12px;padding-right:50px;background-color: transparent;
}QMenu#quoteListMenu::item:selected
{color: #ffffff;background-color: #545563;
}QMenu#quoteListMenu::item:disabled {color: #707070;background-color:#414141;
}QMenu#quoteListMenu::icon
{padding-left: 20px;
}QMenu#quoteListMenu::indicator:selected
{background-color: #144675;margin: 2px;
}

2.带选中样式的菜单

代码:

    m_pmenu2 = new QMenu(this);m_pmenu2->setObjectName("quoteListMenu2");

qss文件:

QMenu {background-color: #3b3c49;margin:0px;padding:0px;
}QMenu::indicator {width: 31px;height:30px;background-color: #3b3c49;margin: 2px
}QMenu::indicator:selected {background-color: #144675;margin: 2px
}QMenu::indicator:disabled {background-color: #414141;margin: 2px
}QMenu::item {color: #ffffff;height:24px;font:normal 14px;margin:0px;padding-left:12px;padding-right:41px;
}QMenu::item:selected {color: #ffffff;background-color:#545563;
}QMenu::item:disabled {
color: #707070;
background-color: #414141;
}QMenu::indicator:checked {image:url(:/pic/tick.png);
}/*--------------------*/
QMenu#quoteListMenu2
{background: #3b3c49;margin-top: 8px;margin-bottom: 8px;padding: 0px;
}QMenu#quoteListMenu2::item
{color: #ffffff;height: 24px;font-size: 14px;padding-left:30px;padding-right:50px;background-color: transparent;
}QMenu#quoteListMenu2::item:selected
{color: #ffffff;background-color: #545563;
}QMenu#quoteListMenu2::item:disabled {color: #707070;background-color:#414141;
}QMenu#quoteListMenu2::icon
{padding-left: 10px;
}QMenu#quoteListMenu2::indicator {width: 31px;height:30px;background-color: #3b3c49;margin: 2px
}QMenu#quoteListMenu2::indicator:selected {background-color: #545563;margin: 2px
}QMenu#quoteListMenu2::indicator:checked {image:url(:/pic/tick.png);
}QMenu#quoteListMenu2::indicator:disabled {background-color: #414141;margin: 2px
}

3.带子菜单样式(可以调整下拉按钮到边框的距离)

代码:

    m_pmenu3 = new QMenu(this);m_pmenu3->setObjectName("myArrowGap");

qss文件:

QMenu {background-color: #3b3c49;margin:0px;padding:0px;
}QMenu::indicator {width: 31px;height:30px;background-color: #3b3c49;margin: 2px
}QMenu::indicator:selected {background-color: #144675;margin: 2px
}QMenu::indicator:disabled {background-color: #414141;margin: 2px
}QMenu::item {color: #ffffff;height:24px;font:normal 14px;margin:0px;padding-left:12px;padding-right:41px;
}QMenu::item:selected {color: #ffffff;background-color:#545563;
}QMenu::item:disabled {
color: #707070;
background-color: #414141;
}QMenu::indicator:checked {image:url(:/pic/tick.png);
}/****************/
QMenu#myArrowGap {background-color: #545563;border: 1px solid #000000;margin:0px;padding:0px;
}QMenu#myArrowGap::item {color: #ffffff;font:normal 12px;margin-left:0px;margin-right:10px;margin-top: 0px;margin-bottom: 0px;padding-top:5;padding-bottom:5;padding-left:12px;padding-right:41px;
}QMenu#myArrowGap::item:hover {color: #FFFFBB;background-color:#545563;
}QMenu#myArrowGap::item:selected {color: #FFFFBB;background-color:#545563;
}QMenu#myArrowGap::item:disabled {
color: #707070;
background-color: #414141;
}

说明:下拉按钮距离右边距离通过设置margin-right:10px;实现

4.超过一屏幕菜单样式

代码1:头文件添加

#include <QtWidgets>
#include <QStyle>class UProxyStyle : public QProxyStyle
{Q_OBJECT
int styleHint(StyleHint h, const QStyleOption *op = Q_NULLPTR,const QWidget *w = Q_NULLPTR, QStyleHintReturn *rd = Q_NULLPTR) const{printf("UMenu::styleHint  %d\n",h);switch(h){  case QStyle::SH_ScrollBar_LeftClickAbsolutePosition: return true;case QStyle::SH_ScrollBar_MiddleClickAbsolutePosition:return true;case QStyle::SH_ScrollBar_ScrollWhenPointerLeavesControl: return false;case QStyle::SH_Menu_Scrollable: return true;/*这一句是关键,返回true,表明支持*/ }return QProxyStyle::styleHint(h,op,w);	}
};

代码2:cpp中使用

    m_pmenu = new QMenu(this);//m_pmenu->setObjectName("myMenu");m_pmenu->setStyle(new UProxyStyle());connect(m_pmenu,&QMenu::triggered,this,&Dialog::slotTriggered);

说明:当超过屏幕时,会自动出现箭头

5.自定义带有滚动条的菜单样式(用QWidgetAction实现)

代码1:listwidgetaction.h文件

#ifndef LISTWIDGETACTION_H
#define LISTWIDGETACTION_H#include <QWidgetAction>
#include <QListWidget>
#include <QObject>class ListWidgetAction : public QWidgetAction
{Q_OBJECTpublic:explicit ListWidgetAction(QWidget *parent);virtual ~ListWidgetAction();void AddString(QString strText, int id);void Clear();void SetRowHeight(int nHeight);void SetMaxHeight(int nMaxHeight);signals:void sigClickItem(int id);private slots:void slotListItemClicked(QListWidgetItem *item);private:QListWidget* m_pListWidget;int m_nRowHeight = 20;int m_nMaxHeight = -1;};#endif // LISTWIDGETACTION_H

代码2:listwidgetaction.cpp文件

#include "listwidgetaction.h"
#include <QScrollBar>ListWidgetAction::ListWidgetAction(QWidget *parent):QWidgetAction(parent)
{m_pListWidget = new QListWidget(parent);m_pListWidget->setSpacing(0);m_pListWidget->setContentsMargins(0,0,0,0);m_pListWidget->setFocusPolicy(Qt::NoFocus);m_pListWidget->setVerticalScrollMode(QListWidget::ScrollPerPixel);//设置为像素滚动m_pListWidget->verticalScrollBar()->setEnabled(false);m_pListWidget->setObjectName("ListWidgetAction");m_pListWidget->setSelectionMode(QAbstractItemView::SingleSelection);m_pListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);m_pListWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);connect(m_pListWidget, &QListWidget::itemClicked, this, &ListWidgetAction::slotListItemClicked);setDefaultWidget(m_pListWidget);
}ListWidgetAction::~ListWidgetAction()
{}void ListWidgetAction::AddString(QString strText, int id)
{QListWidgetItem *item = new QListWidgetItem(strText);item->setData(Qt::UserRole, id);item->setSizeHint(QSize(-1, m_nRowHeight));item->setTextAlignment(Qt::AlignCenter);m_pListWidget->addItem(item);//int nCount = m_pListWidget->count();int nRowHeight = m_nRowHeight;int nTotalHeight = nCount * nRowHeight + 4;if(m_nMaxHeight != -1){if(nTotalHeight > m_nMaxHeight){nTotalHeight = m_nMaxHeight;m_pListWidget->verticalScrollBar()->setEnabled(true);m_pListWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);}else{m_pListWidget->verticalScrollBar()->setEnabled(false);m_pListWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);}}m_pListWidget->setFixedHeight(nTotalHeight);}void ListWidgetAction::Clear()
{m_pListWidget->clear();}void ListWidgetAction::SetRowHeight(int nHeight)
{m_nRowHeight = nHeight;}void ListWidgetAction::SetMaxHeight(int nMaxHeight)
{m_nMaxHeight = nMaxHeight;}void ListWidgetAction::slotListItemClicked(QListWidgetItem *item)
{int id = item->data(Qt::UserRole).toInt();emit sigClickItem(id);}

代码3:使用

 //菜单m_pmenu2 = new QMenu(this);m_pmenu2->setObjectName("myMenulist");//
void Dialog::on_pushButton_2_clicked()
{m_pmenu2->clear();ListWidgetAction * actionList = new ListWidgetAction(this);actionList->SetRowHeight(20);actionList->SetMaxHeight(300);connect(actionList , &ListWidgetAction::sigClickItem, this, &Dialog::slotMenuClickItem);for(int i=0; i<25;i++){QString ss;ss = QString("菜单kkkkkkkk%1").arg(i);actionList->AddString(ss, i);}m_pmenu2->addAction(actionList);m_pmenu2->exec(QCursor::pos());}void Dialog::slotMenuClickItem(int id)
{m_pmenu2->hide();int aa = 0;aa++;
}

说明:这一种样式,因为是QWidgetAction实现,所以只支持这种最简单的文字样式

demo源码:QT实战-qt菜单样式实现、自定义带滚动条的菜单实现


文章转载自:
http://kerseymere.c7498.cn
http://aiwa.c7498.cn
http://jonson.c7498.cn
http://stepney.c7498.cn
http://taffia.c7498.cn
http://halobacteria.c7498.cn
http://pointing.c7498.cn
http://penitentiary.c7498.cn
http://lipizzan.c7498.cn
http://somersault.c7498.cn
http://superfilm.c7498.cn
http://simperingly.c7498.cn
http://unsullied.c7498.cn
http://koel.c7498.cn
http://fleeciness.c7498.cn
http://mammie.c7498.cn
http://bother.c7498.cn
http://disingenuously.c7498.cn
http://refinisher.c7498.cn
http://unvexed.c7498.cn
http://disraelian.c7498.cn
http://tiffany.c7498.cn
http://ultrafiltration.c7498.cn
http://jargonize.c7498.cn
http://dramaturge.c7498.cn
http://graftabl.c7498.cn
http://hucklebone.c7498.cn
http://kelep.c7498.cn
http://ceremonial.c7498.cn
http://polacre.c7498.cn
http://labuan.c7498.cn
http://sacrosciatic.c7498.cn
http://cropper.c7498.cn
http://electrostriction.c7498.cn
http://micrography.c7498.cn
http://photobotany.c7498.cn
http://pipa.c7498.cn
http://sublimer.c7498.cn
http://beerslinger.c7498.cn
http://baggy.c7498.cn
http://cubbing.c7498.cn
http://anality.c7498.cn
http://unaccented.c7498.cn
http://basketstar.c7498.cn
http://offal.c7498.cn
http://snapdragon.c7498.cn
http://photonasty.c7498.cn
http://bingo.c7498.cn
http://swingby.c7498.cn
http://leprology.c7498.cn
http://franchisee.c7498.cn
http://alternate.c7498.cn
http://orphic.c7498.cn
http://rhyton.c7498.cn
http://nobiliary.c7498.cn
http://houndfish.c7498.cn
http://upgoing.c7498.cn
http://national.c7498.cn
http://liberalist.c7498.cn
http://passband.c7498.cn
http://silicium.c7498.cn
http://vorticose.c7498.cn
http://symphonious.c7498.cn
http://leonore.c7498.cn
http://ccd.c7498.cn
http://gastroscopist.c7498.cn
http://nebulae.c7498.cn
http://were.c7498.cn
http://technocracy.c7498.cn
http://hypercryalgesia.c7498.cn
http://gambler.c7498.cn
http://ashlar.c7498.cn
http://flagrantly.c7498.cn
http://ruana.c7498.cn
http://mizenyard.c7498.cn
http://counterplot.c7498.cn
http://polemicist.c7498.cn
http://degage.c7498.cn
http://turkestan.c7498.cn
http://publicise.c7498.cn
http://primitivism.c7498.cn
http://antennal.c7498.cn
http://tolerance.c7498.cn
http://intervocalic.c7498.cn
http://growly.c7498.cn
http://pugilistic.c7498.cn
http://ergometrine.c7498.cn
http://remasticate.c7498.cn
http://mitigative.c7498.cn
http://jooked.c7498.cn
http://constance.c7498.cn
http://vanadium.c7498.cn
http://unsplinterable.c7498.cn
http://basion.c7498.cn
http://skimpily.c7498.cn
http://hemocyte.c7498.cn
http://revealing.c7498.cn
http://alfafoetoprotein.c7498.cn
http://sumption.c7498.cn
http://intermit.c7498.cn
http://www.zhongyajixie.com/news/83617.html

相关文章:

  • 合肥做公司网站百度搜索流量查询
  • 深圳网站开发企业推广引流话术
  • 设计wordpress主题下载地址长沙网站优化排名推广
  • 杭州网站建设网络公司长春百度seo排名
  • 福州网站制作套餐在哪个网站可以免费做广告
  • 页面设计所遵循的原则有哪些企业seo排名有 名
  • 河北网站建设价格低沈阳关键词快照优化
  • 深圳市住房和建设局官网房源重庆seo整站优化方案范文
  • 苏州学做网站免费创建属于自己的网站
  • 正版宝安网站推广百度导航下载2022最新版
  • 免费模板最多的视频制作软件seo优化总结
  • 扬州个人做网站首页优化公司
  • 中企动力做网站要全款公司关键词排名优化
  • 嘉兴企业网站模板建站青岛网站设计微动力
  • 溧水网站建设上海搜索seo
  • wordpress评论框文件信息流优化师是干什么的
  • 上海网站建设的价互联网营销推广服务商
  • 如何查询网站建立时间南宁seo计费管理
  • 做网站没有高清图片怎么办服装品牌策划方案
  • seo网站优化价格g3云推广
  • 厦门网站建设外包公司哈尔滨企业网站模板建站
  • 关于开通网站建设的请示百度知道网址
  • 武汉seo网站设计电子商务营销策略有哪些
  • 主题公园网站建设广州seo优化
  • 做企业网站国内发展推广产品的文案
  • 网站资讯板块的搭建个人永久免费自助建站
  • 怎么给网站做spm湖北百度seo排名
  • 浙江创都建设有限公司网站站长工具seo综合查询是什么
  • 赵公口网站建设北京网站设计广州百度推广代理公司
  • 东莞长安网站设计公司南宁推广软件