找回密码
 立即注册
收起左侧

无标题窗口的改变大小

6
回复
9882
查看
[复制链接]
累计签到:2 天
连续签到:1 天
来源: 2014-12-10 00:08:22 显示全部楼层 |阅读模式
1Qter豆
我去掉了标题栏和状态栏,setWindowFlags(Qt::FramelessWindowHint);然后无法在右下角改变窗口大小了,网上查了下http://blog.csdn.net/feiyan_go/article/details/9303859;按这个地址说的方案也不行,求解决方案。当然  如果不去掉状态栏还是可以右下角改变大小的。代码附上 ;环境 qt5.3.1+msvc2010


附件: 您需要 登录 才可以下载或查看,没有帐号?立即注册

最佳答案

查看完整内容

winEvent该方法在qt5中已删除。对于你的问题可以这么写,其中定义的宏只是大概定义了一个检测误差 mainwindow.cpp: #include "mainwindow.h" #include "ui_mainwindow.h" #include #include #define WINDOW_FRAME_BORDER 4 MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); setWindowFlags(Qt::FramelessWindowHint); } MainWindow::~MainWin ...
回复

使用道具 举报

累计签到:22 天
连续签到:1 天
2014-12-10 00:08:23 显示全部楼层
winEvent该方法在qt5中已删除。对于你的问题可以这么写,其中定义的宏只是大概定义了一个检测误差
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <Windows.h>
#include <WindowsX.h>

#define WINDOW_FRAME_BORDER 4


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowFlags(Qt::FramelessWindowHint);
}

MainWindow::~MainWindow()
{
    delete ui;
}

bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
    return winEvent( (MSG*)message,result );
}

bool MainWindow::winEvent(MSG *message, long *result)
{
    switch(message->message)
        {
        case WM_NCHITTEST:
            int xPos = GET_X_LPARAM(message->lParam) - this->frameGeometry().x();
            int yPos = GET_Y_LPARAM(message->lParam) - this->frameGeometry().y();
            if(this->childAt(xPos,yPos) == 0)
            {
                *result = HTCAPTION;
            }else{
                //return false;
            }

            int nLeft = 0;
            int nTop = 0;
            int nRight = width();
            int nBottom = height();
            bool bAdditional = false;

            if( WINDOW_FRAME_BORDER > qAbs( nLeft - xPos ) )
            {
                bAdditional = true;
                *result = HTLEFT;
            }

            if( WINDOW_FRAME_BORDER > qAbs( nRight - xPos ) )
            {
                bAdditional = true;
                *result = HTRIGHT;
            }

            if( WINDOW_FRAME_BORDER > qAbs( nTop - yPos ) )
            {
                if( bAdditional )
                {
                    *result = HTTOPRIGHT;
                }
                else
                {
                    *result = HTTOP;
                }
            }

            if( WINDOW_FRAME_BORDER > qAbs( nBottom - yPos ) )
            {
                if( bAdditional )
                {
                    *result = HTBOTTOMRIGHT;
                }
                else
                {
                    *result = HTBOTTOM;
                }
            }

            return true;
        }
        return false;
}

mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
protected:
    bool winEvent(MSG *message, long *result);
    bool nativeEvent(const QByteArray & eventType, void * message, long * result);
};

#endif // MAINWINDOW_H
回复

使用道具 举报

累计签到:597 天
连续签到:1 天
2014-12-10 19:11:44 显示全部楼层
  mingw+qt4.7.4   亲测方案二  可以用

注意要挂:#include "windowsx.h"
               #include "windows.h"
还有setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint
                              | Qt::WindowMinMaxButtonsHint);
回复

使用道具 举报

累计签到:22 天
连续签到:1 天
2014-12-11 17:17:27 显示全部楼层
上边的代码对右上和右下貌似判断有问题,你自己改下吧
回复

使用道具 举报

累计签到:2 天
连续签到:1 天
2014-12-15 21:06:49 显示全部楼层
shasidaran 发表于 2014-12-10 19:11
mingw+qt4.7.4   亲测方案二  可以用

注意要挂:#include "windowsx.h"

非常感谢!已经可以了!
回复

使用道具 举报

累计签到:2 天
连续签到:1 天
2014-12-15 21:24:37 显示全部楼层
leo_cao 发表于 2014-12-11 17:17
上边的代码对右上和右下貌似判断有问题,你自己改下吧

感谢!刚刚回复错人了
回复

使用道具 举报

尚未签到

2015-11-8 02:11:13 显示全部楼层
怎么写的啊.................................................
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了