Qt杂项设置(QLabel超链接、图片缩放、窗口不在任务栏显示并置顶等)

1.使用代码设置渐变

QLinearGradient linearGrad(QPointF(0, 0), QPointF(200, 200));
linearGrad.setColorAt(0, Qt::blue);
linearGrad.setColorAt(1, Qt::white);
linearGrad.setCoordinateMode(QGradient::StretchToDeviceMode);
QBrush brush(linearGrad);
item1->setBackground(brush);

2.QPixmap图片的缩放

Qsize picSize(600,400);
//将pixmap缩放成picSize大小然后保存在scaledPixmap中
按比例缩放:
QPixmap scaledPixmap = pixmap.scaled(picSize, Qt::KeepAspectRatio);
不按照比例缩放
QPixmap scaledPixmap = pixmap.scaled(picSize);

3.设置窗口不在任务栏显示并置顶

setWindowFlags(Qt::Tool | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint
);

4.QLineEdit去掉右键菜单

_ui->_passwordEdit->setContextMenuPolicy(Qt::NoContextMenu);//去掉右键菜单

5.去除QString中的空格

QString str = "  lots\t of\nwhitespace\r\n ";
 str = str.trimmed();
 // str == "lots\t of\nwhitespace"

 QString str = "  lots\t of\nwhitespace\r\n ";
 str = str.simplified();
 // str == "lots of whitespace";

6.QLabel实现超链接

ui->_userWebConnect->setOpenExternalLinks(true);
ui->_userWebConnect->setText("<a href = \"http://zkuyun.com/\>显示的内容</a>");

 7.QTreeView去掉父节点的下拉

treeView->setRootIsDecorated(false);

// UI控件里,在右边的设置属性里找到 QTreeView那栏,将rootIs Decorated 复选框,不要勾选

8.设置不透明关键字

  border-color: rgba(255, 0, 0, 75%);

9.QListview行之间颜色不同设置

  先在stylesheet上加  alternate-background-color:#e1eff8;

  然后在listview控件上,勾选上alternatingRowColors属性框

 

转载于:https://www.cnblogs.com/zw-h/p/4032992.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值