一些代码
- 窗口全屏
showFullScreen(); //全屏
- 设置窗口透明度,1是不透明,0是透明
setWindowOpacity(0.1); //设置窗口透明度
- Qt子控件阴影效果:
QGraphicsDropShadowEffect * shadow = new QGraphicsDropShadowEffect(this);
shadow->boundingRectFor(this->ui->httpReplyContent->rect().adjusted(5,5,5,5));
shadow->setOffset(-5,5); //设置阴影方向
shadow->setColor(Qt::gray); //设置阴影颜色
shadow->setBlurRadius(10); //设置阴影边缘模糊
this->ui->httpReplyContent->setGraphicsEffect(shadow);
效果:
- 去掉标题栏
setWindowFlags(Qt::FramelessWindowHint); //去掉标题栏
- 去掉标题栏后,设置窗口可用鼠标移动:去掉标题栏后处理鼠标消息,鼠标移动时移动窗口
.h
protected:
void mouseMoveEvent(QMouseEvent * event);
void mousePressEvent(QMouseEvent * event);
void mouseReleaseEvent(QMouseEvent * event);
private:
Ui::MainWindow *ui;
//设置拖动
QPoint m_ptPress;
bool m_bLeftBtnPress;
.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
m_bLeftBtnPress = false;
ui->setupUi(this);
setWindowFlags(Qt::FramelessWindowHint); //去掉标题栏
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton)
{
m_ptPress = event->globalPos(); //记录按下位置
m_bLeftBtnPress = true;
}
event->ignore();
}
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
if(m_bLeftBtnPress) //移动窗口
{
move(pos() + event->globalPos() - m_ptPress);
m_ptPress = event->globalPos();
}
event->ignore();
}
void MainWindow::mouseReleaseEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton)
m_bLeftBtnPress = false;
event->ignore();
}