• 15613阅读
  • 10回复

【问答】如何去掉窗体边框 [复制链接]

上一主题 下一主题
离线XChinux
 

只看楼主 倒序阅读 楼主  发表于: 2005-08-31
答:使用setWindowFlags(Qt::SplashScreen)或者setWindowFlags(Qt::FramelessWindowHint)函数,如下面的代码:

#include <QApplication>
#include <QDialog>
int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    QDialog dialog;
    dialog.setWindowFlags(Qt::SplashScreen);
    return dialog.exec();
}
[ 此贴被XChinux在2005-08-31 10:28重新编辑 ]
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线yfy002

只看该作者 1楼 发表于: 2005-08-31
Qt::Window
| Qt::FramelessWindowHint
also can do
我渴望平静,风却给了我涟漪
我的blog:
http://sungaoyong.cublog.cn
离线XChinux

只看该作者 2楼 发表于: 2005-08-31
对,加上楼上说的。
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线acefunware

只看该作者 3楼 发表于: 2005-09-01
明白了
呵呵
email:acefunware@yahoo.com.cn
blog:http://acefunware.shineblog.com
离线worthing

只看该作者 4楼 发表于: 2005-09-07
各位都是使用哪个版本才能去掉窗体边框?

我使用得2.3.7没有楼上几位提到得功能啊?
离线yfy002

只看该作者 5楼 发表于: 2005-09-07
下面是引用worthing于2005-09-07 16:22发表的:
各位都是使用哪个版本才能去掉窗体边框?
我使用得2.3.7没有楼上几位提到得功能啊?

qt4.0.1都出来了,为什么还要用古董???2.3.7版本的我们也没有,怎么知道如何做呢?如果你购买的是商业版的,应该可以从Trolltech公司获得技术支持啊?
我渴望平静,风却给了我涟漪
我的blog:
http://sungaoyong.cublog.cn
离线worthing

只看该作者 6楼 发表于: 2005-09-07
因为我用的是QTE2.3.7
离线XChinux

只看该作者 7楼 发表于: 2005-09-09
我在qt-interest里面问一下,一位朋友给出了下面的解答方案:

XChinux wrote:
>> Gael Martin 写道:
>>
>
>>>>XChinux wrote:
>>>>
>>>>
>>
>>>>>>but in qt 2.3.7, the function "setWindowFlags()" had not exist,
>>>>>>how can I get the same style of Qt4's splash window style?
>>
>>>>
>>>>
>>>>Cant you just upgrade to QT 4.0.1? Now that it's GPL on all platform
>>>>there's no excuses...
>>>>
>>>>Gael
>
>>
>>   in qtcn.org(http://www.qtcn.org, Chinese Qt Forum),a qter asked
>> this question. and he said he used only 2.3.7(commercial edition),so can
>> not upgrade to Qt 4.0.1。
A previous work of mine is based on Qt 2.3.x (didn't know there existed
a 2.3.7 release?) - it uses a splashscreen which does more or less what
the QSplashScreen does today. It's based on some older article which
appeared in the Qt Quarterly (you might find it on TrollTech's webpage).
Source code here: http://www.pointshop3d.com - the class is called
SplashScreen (POINTSHOP/src/Utilities/UserMessages/src/SplashScreen.h)
The trick is something like this:
// Qt 2.x
splash = new QLabel (0, "splash", Qt::WDestructiveClose |
Qt::WStyle_Customize | Qt::WStyle_NoBorder);
splash->setLineWidth(0);
splash->setMidLineWidth(0);
I have attached the relevant source code for convenience. You need to
hardcode a nice *.png path for use as splash image and it has a single
dependency on a "Version" class which provides - a version number ;)
Should be easy to adjust to your needs.
Cheers, Oliver
//
// Title:   SplashScreen.cpp
// Created: Mon Sep 23 14:13:25 2002
// Authors: Oliver Knoll, Mark Pauly, Matthias Zwicker
//
// Copyright (c) 2001, 2002, Computer Graphics Lab, ETH Zurich
//
// This file is part of the Pointshop3D system.
// See http://www.pointshop3d.com/ for more information.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
// MA 02111-1307, USA.
//
// Contact info@pointshop3d.com if any conditions of this
// licensing are not clear to you.
//
#include <qapplication.h>
#include <qlabel.h>
#include <qstring.h>
#include <qpainter.h>
#include "../../src/Version.h"
#include "SplashScreen.h"
// ******
// global
// ******
// the single SplashScreen instance, only
// accesible by getInstance() and
// destroyInstance()
static SplashScreen *instance = 0;
// *******************
// private c'tor/d'tor
// *******************
SplashScreen::SplashScreen() {
     QRect rect;
     
     splash = new QLabel (0, "splash", Qt::WDestructiveClose | Qt::WStyle_Customize | Qt::WStyle_NoBorder);
     splash->setLineWidth(0);
     splash->setMidLineWidth(0);
     splashPixmap = QPixmap ("Resources/Splash.png");
     splash->setPixmap (splashPixmap);
                 
     splash->adjustSize();
     splash->setCaption ("PointShop");
     rect = QApplication::desktop()->geometry();
     splash->move (rect.center() - splash->rect().center());      
}
SplashScreen::~SplashScreen() {
     delete splash;
}
// **************
// public methods
// **************
SplashScreen *SplashScreen::getInstance() {
     if (instance == 0) {
           instance = new SplashScreen();
     }
     return instance;
}
void SplashScreen::destroyInstance() {
     if (instance != 0) {
           delete instance;
     }
     instance = 0;
}
void SplashScreen::showText (const QString text) {
     QPainter painter;            
     painter.begin (splash);
     // clear previous text
     painter.setBackgroundColor (Qt::white);
     painter.eraseRect ((int)(0.05f * (float)splashPixmap.width() + 0.5f),
                      (int)(0.75f * (float)splashPixmap.height() + 0.5f) - painter.font().pixelSize(),
                                splashPixmap.width() - (int)(0.10f * (float)splashPixmap.width() + 0.5f),
                                (int)(1.5f * painter.font().pixelSize()));
     painter.setPen (Qt::black);
     painter.drawText ((int)(0.05f * (float)splashPixmap.width() + 0.5f),
                    (int)(0.75f * (float)splashPixmap.height() + 0.5f),
                              text);
     painter.end();
}
void SplashScreen::show() {
     QPainter painter;            
     splash->show();
     splash->repaint (false);
     QApplication::flushX();
     
     painter.begin (splash);
     painter.setPen (Qt::gray);
     painter.drawText ((int)(0.8f   * (float)splashPixmap.width() + 0.5f),
                    (int)(0.035f * (float)splashPixmap.height() + 0.5f),
                              "Version " + Version::toString());      
     painter.drawText ((int)(0.025f * (float)splashPixmap.width() + 0.5f),
                    (int)(0.990f * (float)splashPixmap.height() + 0.5f),
                              Version::getVersionDate().toString() + "   \"" + Version::getCodeName() + "\"");
     painter.drawText ((int)(0.05f * (float)splashPixmap.width() + 0.5f),
                    (int)(0.8f * (float)splashPixmap.height() + 0.5f),
                              "PointShop by Oliver Knoll, Matthias Zwicker & Mark Pauly");
     painter.drawText ((int)(0.05f * (float)splashPixmap.width() + 0.5f),
                    (int)(0.8f * (float)splashPixmap.height() + 1.2f * (float)painter.font().pixelSize() + 0.5f),
                              "OpenGL renderer extensions and SFL file format by Tim Weyrich");
     painter.drawText ((int)(0.05f * (float)splashPixmap.width() + 0.5f),
                    (int)(0.8f * (float)splashPixmap.height() + 2.4f * (float)painter.font().pixelSize() + 0.5f),
                              "(c) 2001, 2002");
#if defined _DEBUG
     painter.setPen (Qt::red);
     painter.drawText ((int)(0.9f * (float)splashPixmap.width() + 0.5f),
                    (int)(0.8f * (float)splashPixmap.height() + 0.5f),
                              "DEBUG");
#endif
     painter.end();      
     
}
void SplashScreen::hide() {
     splash->hide();
}
// Some Emacs-Hints -- please don't remove:
//
// Local Variables:
// mode:C++
// tab-width:4
// End:
//
// Title:   SplashScreen.h
// Created: Mon Sep 23 14:13:19 2002
// Authors: Oliver Knoll, Mark Pauly, Matthias Zwicker
//
// Copyright (c) 2001, 2002, Computer Graphics Lab, ETH Zurich
//
// This file is part of the Pointshop3D system.
// See http://www.pointshop3d.com/ for more information.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
// MA 02111-1307, USA.
//
// Contact info@pointshop3d.com if any conditions of this
// licensing are not clear to you.
//
#ifndef __SPLASHSCREEN_H_
#define __SPLASHSCREEN_H_
#include <qlabel.h>
#include <qstring.h>
#include <qpixmap.h>
#include <qimage.h>
#include "../../src/UtilitiesDLL.h"
/**
* This class implements a nice splash screen, which pops up
* before the application starts (I always wanted to do such
* a thing ;)
*
* @author Oliver Knoll
* @version 1.2
*/
class SplashScreen {
public:
     /**
      * This method creates an instance of this <code>SplashScreen</code>, if necessary,
      * and returns it. Only one instance at a time exists (singleton pattern).
      *
      * @return an instance of this <code>SplashScreen</code>
      */
     UTILITIES_API static SplashScreen *getInstance();
     /**
      * Destroys the instance of this <code>SplashScreen</code>, if there
      * is one. Also <code>hide</code>s the splash screen, if not already
      * done.
      *
      * @see #hide
      */
     UTILITIES_API static void destroyInstance();
     /**
      * Shows the splash screen.
      *
      * @see #hide
      */
     UTILITIES_API void show();
     /**
      * Hides the splash screen.
      *
      * @see #show
      */
     UTILITIES_API void hide();
     /**
      * This method shows a text while this <code>SplashScreen</code> is showing.
      *
      * @param text
      *     a <code>QString</code> which contains the text to be shown; the
      *     text must have reasonable length, else it is clipped
      */
     UTILITIES_API void showText (const QString text);
private:
     QLabel *splash;
     QPixmap splashPixmap;
     QImage splashImage;
     // singleton pattern
     SplashScreen();
     virtual ~SplashScreen();
};
#endif // __SPLASHSCREEN_H_
// Some Emacs-Hints -- please don't remove:
//
// Local Variables:
// mode:C++
// tab-width:4
// End:
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线worthing

只看该作者 8楼 发表于: 2005-09-09
谢谢版主,我试试。我真菜,英文不行,在qt-interest和qtforum.org中都不好意思发言。
离线running
只看该作者 9楼 发表于: 2005-09-09
qt-interest的网址多少啊?谢谢了!!!
离线XChinux

只看该作者 10楼 发表于: 2005-09-09
qt-interest是新闻组
nntp://nntp.trolltech.com
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
快速回复
限100 字节
 
上一个 下一个