QT:#include 不工作/失效

写程序时,

头文件中的

#include <QFile> 失效,导致其他#include 语句失败,很悲催

解决办法如下:

#include <QFile> 修改成 #include <QFile.h>

#pragma execution_character_set("utf-8") #include "customControls/switchButton.h" #include "qpainter.h" #include "qdebug.h" ImageSwitch::ImageSwitch(QWidget *parent) : QWidget(parent) { isChecked = false; buttonStyle = ButtonStyle_2; imgOffFile = ":/new/prefix1/image/button/btncheckoff.png"; imgOnFile = ":/new/prefix1/image/button/btncheckon.png"; imgFile = imgOffFile; } void ImageSwitch::mousePressEvent(QMouseEvent *) { imgFile = isChecked ? imgOffFile : imgOnFile; isChecked = !isChecked; emit checkedChanged(isChecked); this->update(); } void ImageSwitch::paintEvent(QPaintEvent *) { QPainter painter(this); painter.setRenderHints(QPainter::SmoothPixmapTransform); QImage img(imgFile); img = img.scaled(this->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); //按照比例自动居中绘制 int pixX = rect().center().x() - img.width() / 2; int pixY = rect().center().y() - img.height() / 2; QPoint point(pixX, pixY); painter.drawImage(point, img); } QSize ImageSwitch::sizeHint() const { return QSize(87, 28); } QSize ImageSwitch::minimumSizeHint() const { return QSize(87, 28); } bool ImageSwitch::getChecked() const { return isChecked; } void ImageSwitch::setChecked(bool isChecked) { if (this->isChecked != isChecked) { this->isChecked = isChecked; imgFile = isChecked ? imgOnFile : imgOffFile; this->update(); } } ImageSwitch::ButtonStyle ImageSwitch::getButtonStyle() const { return this->buttonStyle; } void ImageSwitch::setButtonStyle(const ImageSwitch::ButtonStyle &buttonStyle) { if (this->buttonStyle != buttonStyle) { this->buttonStyle = buttonStyle; if (buttonStyle == ButtonStyle_1) { imgOffFile = ":/new/prefix1/image/button/btncheckoff.png"; imgOnFile = ":/new/prefix1/image/button/btncheckon.png"; this->resize(120, 35); } /*else if (buttonStyle == ButtonStyle_2) { imgOffFile = ":/new/prefix1/image/imageswitch/btncheckoff2.png"; imgOnFile = ":/new/prefix1/image/imageswitch/btncheckon2.png"; this->resize(87, 28); } else if (buttonStyle == ButtonStyle_3) { imgOffFile = ":/new/prefix1/image/imageswitch/btncheckoff3.png"; imgOnFile = ":/new/prefix1/image/imageswitch/btncheckon3.png"; this->resize(96, 38); }*/ imgFile = isChecked ? imgOnFile : imgOffFile; setChecked(isChecked); this->update(); updateGeometry(); } } 上述是Qt中的自定义开关按钮,还需要新的需求:需要设置开关按钮的互斥性
最新发布
04-01
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值