- 
UID:141710 
 
- 
- 注册时间2013-03-15
 
- 最后登录2017-02-27
 
- 在线时间57小时
 
 
 
- 
- 发帖29
 
- 搜Ta的帖子
 
- 精华0
 
- 金钱290
 - 威望39
 - 贡献值0
 - 好评度29
 
 
 
- 
访问TA的空间加好友用道具
 
 
 
 
 
 
 
 | 
 回 roywillow 的帖子 
 
roywillow:你试试直接用win32 api创建一个窗口试试?如果这个能办到的话那就是qt自己的问题了    
 这个我试过了. 原生的win32窗口是没有问题的 我也跟了qt的源码, Qt在updatelayeredwindow时, 一定要Frameless, 所以就没法解决了.  不知道yy的界面是如何解决的 这是我的测试代码, 麻烦看看 - test2.h
 - #include <QWidget>
 -  
 - class test2 : public QWidget
 - {
 -  Q_OBJECT
 -  
 - public:
 -  test2(QWidget *parent);
 -  ~test2();
 -  
 -  public slots:
 -   void OnBtnClicked();
 -  
 - protected:
 -  bool nativeEvent( const QByteArray & eventType, void * message, long * result );
 -  void paintEvent(QPaintEvent*);
 -  bool event(QEvent * event);
 -  
 -  
 -  // wm msg handler
 -  bool HandleGetMinMaxInfoMsg(MSG *msg, long *result);  
 -  
 - private:
 -  
 - };
 
 - test2.cpp
 - #include "test2.h"
 - #include <Windows.h>
 - #include <QEvent>
 - #include <QDebug>
 - #include <QDesktopWidget>
 - #include <windowsx.h>
 - #include <QWindow>
 - #include <QSurfaceFormat>
 - #include <QPushButton>
 - #include <QPainter>
 - #include <QApplication>
 -  
 - test2::test2(QWidget *parent)
 -  : QWidget(parent)
 - {
 -  QPushButton *pbn = new QPushButton("test", this);
 -  pbn->move(100, 100);
 -  connect(pbn, SIGNAL(clicked()), this, SLOT(OnBtnClicked()));
 -  
 -  setWindowFlags(Qt::FramelessWindowHint | Qt::Window );
 -  setAttribute(Qt::WA_TranslucentBackground);
 -  
 - }
 -  
 - test2::~test2()
 - {
 -  
 - }
 -  
 - bool test2::event(QEvent * e)
 - {
 -  if(e->type() == QEvent::WinIdChange)
 -  {
 -   HWND hWnd = (HWND)this->winId();
 -   LONG lStyle = ::GetWindowLong(hWnd, GWL_STYLE);
 -   ::SetWindowLong(hWnd, GWL_STYLE, lStyle  | WS_OVERLAPPED | WS_THICKFRAME);
 -  }
 -  return QWidget::event(e);
 - }
 -  
 -  
 - bool test2::nativeEvent( const QByteArray & eventType, void * message, long * result )
 - {
 -  MSG *msg = (MSG *)message;
 -  const int captionHeight = 32;
 -  const int frameWidth = 5;
 -  
 -  switch (msg->message )
 -  {
 -  
 -  case WM_GETMINMAXINFO :
 -   HandleGetMinMaxInfoMsg(msg, result);
 -   *result = 0;
 -   return true;
 -  }
 -  
 -  return QWidget::nativeEvent(eventType, message, result);
 - }
 -  
 - void test2::paintEvent( QPaintEvent* )
 - {
 -  QPainter painter(this);
 -  
 -  HWND hWnd = (HWND)this->winId();
 -  RECT winRect;
 -  ::GetWindowRect(hWnd, &winRect);
 -  QRect qWinRect = QRect(0, 0, winRect.right - winRect.left, winRect.bottom - winRect.top);  
 -  
 -  QRect rc = rect();
 -  qDebug () << "paintevent" << rc  << qWinRect;
 -  
 -  painter.fillRect(rc, QColor(0,0,0));
 -  rc.adjust(6, 30, -6, -6);
 -  painter.fillRect(rc, QColor(0, 0, 255, 250));
 -  
 -  
 - }
 -  
 - bool test2::HandleGetMinMaxInfoMsg( MSG *msg, long *result )
 - {
 -  QRect maxRect = QApplication::desktop()->availableGeometry();
 -  QSize szMin = this->minimumSize();
 -  QSize szMax = this->maximumSize();
 -  PMINMAXINFO lpMMI = (PMINMAXINFO)msg->lParam;
 -  lpMMI->ptMaxSize.x = maxRect.width();  
 -  lpMMI->ptMaxSize.y = maxRect.height();
 -  lpMMI->ptMaxPosition.x = 0;
 -  lpMMI->ptMaxPosition.y = 0;
 -  lpMMI->ptMinTrackSize.x = szMin.width();
 -  lpMMI->ptMinTrackSize.y = szMin.height();
 -  lpMMI->ptMaxTrackSize.x = szMax.width();
 -  lpMMI->ptMaxTrackSize.y = szMax.height();
 -  
 -  return true;  
 -  
 - }
 -  
 - void test2::OnBtnClicked()
 - {
 -  static bool bMin = false;
 -  bMin = !bMin;
 -  
 -  if(bMin)
 -  {
 -   showMaximized();
 -  }
 -  else
 -  {
 -   showNormal();
 -  }
 - }
 
  
 
 
 |