qt最大化和还原实现_如何绘制Qt中的关闭,最小化和最大化按钮?

I created a this->setWindowFlags(Qt::FramelessWindowHint); and so there is no title bar. Therefore, I am implementing my own. I wanted to know, however, before I continue whether there is a standard way to add the close, minimize, and maximize buttons in a native-os looking way (i.e. on windows it should look like the windows close buttons and the same for osx and linux).

解决方案

QStyle take a lot of standard icons base on OS style. You can get this icon from current OS style and then draw it by your self.

This is a simple implementation for reference.

class TitleBar : public QWidget

{

Q_OBJECT

public:

explicit TitleBar(QWidget *parent = 0)

:QWidget(parent)

{

QStyle *style = qApp->style();

QIcon closeIcon = style->standardIcon(QStyle::SP_TitleBarCloseButton);

QIcon maxIcon = style->standardIcon(QStyle::SP_TitleBarMaxButton);

QIcon minIcon = style->standardIcon(QStyle::SP_TitleBarMinButton);

QPushButton *min = new QPushButton(this);

QPushButton *max = new QPushButton(this);

QPushButton *close = new QPushButton(this);

min->setIcon(minIcon);

max->setIcon(maxIcon);

close->setIcon(closeIcon);

QHBoxLayout *layout = new QHBoxLayout(this);

layout->setSpacing(0);

layout->addWidget(min);

layout->addWidget(max);

layout->addWidget(close);

setLayout(layout);

}

};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值