0

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.

Community
  • 1
  • 1
haro39
  • 1
  • 1
  • 1

1 Answers1

0

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.

csguth
  • 569
  • 3
  • 18
  • Thanks a lot for your answer csguth! Would you mine explaining to me how to do this in code? Often times I am not using Qt Designer. – haro39 Apr 15 '15 at 14:48
  • I've used this code - QList allToolBars = mainWindow->findChildren(); foreach(QToolBar *tb, allToolBars) { // This does not delete the tool bar. mainWindow->removeToolBar(tb); } But the problem is ONLY the top bar is being removed, not the bottom one. Do you know how I can remove the bottom one in code? – haro39 Apr 15 '15 at 14:54
  • OK, to delete the statusBar you can do delete ui->statusBar !! So that almost solves everything but my topside border is still around 4 px and the rest of the borders are 1px, do you know how to fix that? Thanks again! – haro39 Apr 15 '15 at 15:00