PySide6.QtWidgets import QApplication, QHBoxLayout, QLayout, QMainWindow, QPushButton, QScrollArea, QStyle __init__() self.setWindowTitle('Hello, QStyle Icons!') v_main_layout = QVBoxLayout() count = 0 h_layout = QHBoxLayout() for pixmap in QStyle.StandardPixmap
4, -(option.rect.width() / 2 + 4) , -4); // button1->text = "X"; button1->state |= QStyle option.palette.highlight()); } painter->restore(); QApplication::style()->drawControl(QStyle ::CE_PushButton, buttons->first, painter); QApplication::style()->drawControl(QStyle::CE_PushButton if (btns->first->rect.contains(e->x(), e->y())) { btns->first->state |= QStyle if (btns->first->rect.contains(e->x(), e->y())) { btns->first->state &= (~QStyle
继承QProxyStyle 为了保持与系统或部件所使用的样式一致,应当选择继承QProxyStyle而非QStyle及其它(QCommonStyle等)。 class TreeViewStyle : public QProxyStyle { Q_OBJECT public: explicit TreeViewStyle(QStyle * w->isEnabled() : (vopt->state & QStyle::State_Enabled)) ? & QStyle::State_Selected) && proxy()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, opt, w)) w->isEnabled() : (vopt->state & QStyle::State_Enabled)) ?
opt.widget->style() : QApplication::style(); style->drawControl(QStyle::CE_ItemViewItem, &opt state & QStyle :: State_HasFocus ) { state ^= QStyle :: State_HasFocus; } And of course, it paints everything through QStyle. Complete control to QStyle. If having to write a custom QStyle or a custom delegate sounds daunting, just use style sheets.
为了改变文字的方向,我们需要自定义tabBar的样式,QProxyStyle这个类就可以帮助我们实现,QProxyStyle覆盖QStyle(默认的系统样式),用于动态覆盖绘图或其他特定的样式行为。 QWidget *widget) const { QSize s=QProxyStyle::sizeFromContents(type,option,size,widget); if(type==QStyle qstyleoption_cast<const QStyleOptionTab *>(option)){ QRect allRect=tab->rect; if(tab->state&QStyle QTextOption option; option.setAlignment(Qt::AlignCenter); if(tab->state&QStyle
/ option:选项,用来绘制控件所需的所有参数比如option.rect(设置组件大小位置), option.state(设置组件状态) //其中option. state成员值常见的有: QStyle ::State_Enabled //表示该组件是激活的,可以被用户操作 QStyle::State_On //表示该组件样式是被选上的 QStyle::State_Off //表示该组件样式是未被选中的 QStyle::State_MouseOver //表示表示该组件样式是 :鼠标停留在组件上面的样子 QStyle::State_Sunken //表示该组件样式是:鼠标按压下的组件样子 QStyle::State_HasEditFocus //设置参数 bar.rect.setRect(left, top, width, height); bar.state = QStyle
::PE_IndicatorArrowLeft) { drawArrow(pe, option, painter, widget); } else if (pe == QStyle::PE_IndicatorArrowRight QColor text_color = tb_text_color_.Normal_; QRect text_rect = draw_rect.marginsAdded(margins_); if (QStyle ::State_Selected & option.state) { text_color = tb_text_color_.Selected_; } else if (QStyle::State_MouseOver const QStyleOptionTabV3 &option, QRect draw_rect, QRect real_rect) { painter->setPen(Qt::NoPen); if(QStyle ; helper.FillRoundShadow(painter, draw_rect, tb_bg_color_.Selected_, helper.GetRadius()); } else if(QStyle
button->rect = option.rect.adjusted(4, 4, -4, -4); button->text = "X"; button->state |= QStyle ButtonDelegate *>(this))->m_btns.insert(index, button); } painter->save(); if (option.state & QStyle option.palette.highlight()); } painter->restore(); QApplication::style()->drawControl(QStyle -4).contains(e->x(), e->y()) && m_btns.contains(index)) { m_btns.value(index)->state |= QStyle ).contains(e->x(), e->y()) && m_btns.contains(index)) { m_btns.value(index)->state &= (~QStyle
QStylePainter p(this); QStyleOptionButton option; initStyleOption(&option); p.drawControl(QStyle 所以这段代码改成: QPainter p(this); QStyleOptionButton option; initStyleOption(&option); style()->drawControl(QStyle 走到这里,就不得不一探 QStyle 的究竟了。QStyle 是一个抽象类,头文件因为包含了太多枚举,所以特别长,就不粘了。
在此示例中,我们通过添加新的GUI外观(即,使新的QStyle)来扩展Qt 。插件概述文档中对插件进行了高级介绍。 提供新样式的插件会继承QStylePlugin基类。 "simplestyle.json") public: SimpleStylePlugin() = default; QStringList keys() const; QStyle *create(const QString &key) override; }; keys()返回此插件可以创建的样式名称的列表,同时使用create()这样的字符串并返回与键对应的QStyle 这是create()函数: QStyle *SimpleStylePlugin::create(const QString &key) { if (key.toLower() == "simplestyle
(layout); videoWidget->setPalette(Qt::black); ui->playButton->setIcon(style()->standardIcon(QStyle PlayingState){ m_mediaPlayer->pause(); ui->playButton->setIcon(style()->standardIcon(QStyle } else { m_mediaPlayer->play(); ui->playButton->setIcon(style()->standardIcon(QStyle m_mediaPlayer->state()==QMediaPlayer::PlayingState){ ui->playButton->setIcon(style()->standardIcon(QStyle
{ QSize s = QProxyStyle::sizeFromContents(type, option, size, widget); if (type == QStyle option)) { QRect allRect = tab->rect; if (tab->state & QStyle QTextOption option; option.setAlignment(Qt::AlignCenter); if (tab->state & QStyle
WinPanel 像Panel,但QFrame绘制三维效果的方式和Microsoft Windows 95(及其它)的一样 QFrame::ToolBarPanel 调用QStyle ::drawToolBarPanel() QFrame::MenuBarPanel 调用QStyle::drawMenuBarPanel() QFrame::HLine 作为分隔是有用的) QFrame::VLine 绘制一个竖直线,但没有框任何东西(作为分隔是有用的) QFrame::StyledPanel 调用QStyle ::drawPanel() QFrame::PopupPanel 调用QStyle::drawPopupPanel() QFrame::Shadow这个枚举类型定义了
QWidget *widget) const { QSize s = QProxyStyle::sizeFromContents(type, option, size, widget); if (type == QStyle allRect.setWidth(allRect.width() - 5); allRect.setHeight(allRect.height() - 2); //选中状态 if (tab->state & QStyle 带有弧线矩形 painter->drawRoundedRect(tab->rect, 8, 8); painter->restore(); } //hover状态 else if(tab->state & QStyle
screenHeight = screenGeometry.height(); // 减去窗口边框的大小(根据需要调整) int frameWidth = style()->pixelMetric(QStyle ::PM_DefaultFrameWidth); int titleBarHeight = style()->pixelMetric(QStyle::PM_TitleBarHeight); resize
绘制样式 QStyleOption opt; opt.initFrom(this); QPainter p(this); style()->drawPrimitive(QStyle
if (mouseEvent->button() == Qt::LeftButton) //判断左键 { int value = QStyle
QVideoWidget> // 显示视频 #include <QMediaPlayer> // 播放声音 #include <QPushButton> // 按钮 #include <QStyle = new QPushButton(this); // 设置图标代替文件 playBtn->setIcon(this->style()->standardIcon(QStyle
提示信息文字颜色 QColor bgColor, textColor, tipBgColor, tipTextColor, iconColor; if (option.state & QStyle nav->getParentTextSelectedColor() : nav->getChildTextSelectedColor(); } else if (option.state & QStyle parent && nav->getLineVisible() && lineWidth > 0) { if ((option.state & QStyle::State_Selected ) || (option.state & QStyle::State_MouseOver)) { //设置偏移量,不然上下部分会有点偏移 float offset parent && nav->getTriangleVisible() && triangleWidth > 0) { if ((option.state & QStyle::State_Selected
progressBarOption.text = tr("%1%").arg(progressBarOption.progress); painter->save(); if (option.state & QStyle setBrush(option.palette.highlightedText()); } QApplication::style()->drawControl(QStyle