Qt-demo-basicdrawing

就是使用QPen和QBrush绘制图形,如图

在这里插入图片描述主要使用的类
1-QPen
2-QBrush
3-QSpinBox
4-QComboBox

知识点
QComboBox添加可以这样,把实际类型也添加进去

    penStyleComboBox = new QComboBox;
    penStyleComboBox->addItem(tr("Solid"), static_cast<int>(Qt::SolidLine));
    penStyleComboBox->addItem(tr("Dash"), static_cast<int>(Qt::DashLine));
    penStyleComboBox->addItem(tr("Dot"), static_cast<int>(Qt::DotLine));
    penStyleComboBox->addItem(tr("Dash Dot"), static_cast<int>(Qt::DashDotLine));
    penStyleComboBox->addItem(tr("Dash Dot Dot"), static_cast<int>(Qt::DashDotDotLine));
    penStyleComboBox->addItem(tr("None"), static_cast<int>(Qt::NoPen));

这里为什么static_cast一下,注释一下就知道了,结果如下

 error: 'QVariant::QVariant(Qt::PenStyle)' is private
 根据原理我把static_cast<int> 改成static_cast<double>也可以用。

看下如何使用

    Qt::PenStyle style = Qt::PenStyle(penStyleComboBox->itemData(
            penStyleComboBox->currentIndex(), IdRole).toInt());

它的函数定义是

    QVariant itemData(int index, int role = Qt::UserRole) const;

所以不一定要传给IdRole这个参数,这个参数是干啥用的呢?可以深挖一下,这里掠过。

其他没有什么了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

可峰科技

生活不易

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值