如何绘制Qt中的关闭,最小化和最大化按钮? [英] How do I draw the close, minimize, and maximize buttons in Qt?

查看:1207
本文介绍了如何绘制Qt中的关闭,最小化和最大化按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 this-> setWindowFlags(Qt :: FramelessWindowHint); 因此没有标题栏。因此,我实现自己的。我想知道,然而,在我继续之前是否有一个标准的方式来添加关闭,最小化和最大化按钮在本机os看起来的方式(即在Windows上它应该看起来像窗口关闭按钮和相同的osx和linux)。

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 在OS样式。

这是一个简单的实现,可供参考。

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);
    }
};

这篇关于如何绘制Qt中的关闭,最小化和最大化按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆