简体   繁体   中英

Qt Frameless/Borderless Window (like in Visual Studio UI)

I am trying to implement a frameless window in Qt 5.2 C++.

This answer -would- be perfect for me, but that no longer works in Qt5 - Borderless window in Qt on Windows which supports native features: aero snap, DWM resize and minimization

What I've done is created a basic MainWindow widget, set the properties via stylesheet, and it's almost what I want except for a few things.

This code:

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent, Qt::CustomizeWindowHint ), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //this->setFixedSize(300, 450);
    this->statusBar()->setSizeGripEnabled(true);
    this->setStyleSheet("background-color: white; border: 1px solid red;");
    this->setWindowFlags(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground, true);
}

Will give me -almost- what I want, main problems being -

  1. There is some odd bar at the top, which looks like this. When I right click on the bar, then left click the checkbox, it dissappears. How do I disable this by default? (Please excuse the 3rd party links, StackOverflow does not allow newcomers to host pics here)

http://i57.tinypic.com/2iapqnn.png

  1. As seen, only the side borders are 1 px, and the top/bottom borders are more like 4 px. There is also that odd bar at the bottom (similar to the one at the top, before it gets removed) that I'd like removed. How do I disable the bottom bar, and make sure ALL borders are exactly 1 px wide?

http://i62.tinypic.com/28qsnrk.png

All I want is an empty white, resizeable window with 1 px red borders.

Thank you very much for your help. Have a great day.

There is some odd bar at the top, which looks like this. When I right click on the bar, then left click the checkbox, it dissappears. How do I disable this by default? (Please excuse the 3rd party links, StackOverflow does not allow newcomers to host pics here)

I'ts the toolbar. To remove it: in Qt Design view -> objects list -> right-click on mainToolBar, and then delete it!

As seen, only the side borders are 1 px, and the top/bottom borders are more like 4 px. There is also that odd bar at the bottom (similar to the one at the top, before it gets removed) that I'd like removed. How do I disable the bottom bar, and make sure ALL borders are exactly 1 px wide?

This is your statusBar, do the same as you did to the toolBar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM