2

I'm trying to remove the default Windows titlebar from my Qt window (QT version 5.12.2 and using C++) while still keeping the window borders. I've more or less achieved this using the flag Qt::CustomizeWindowHint. However, this changes the window borders to white lines instead of the default borders.

Example of how the borders look AFTER I've applied the Qt::CustomizeWindowHint flag: enter image description here

As you can see, these are not the normal Windows window borders.

How can I change/edit these boders (i.e. change their color) or how am I able to keep the default Windows window borders while removing the titlebar?

Here's a minimal reproducible example:

main.cpp:

int main(int argc, char* argv[]) {

    QApplication application(argc, argv);
    launcher mainWindow;

    //debugChecks();
    mainWindow.setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::MSWindowsFixedSizeDialogHint);
    mainWindow.setWindowTitle("Test");
    mainWindow.show();

    return application.exec();
}

launcher.h

#pragma once

#include <QtWidgets/QMainWindow>
#include <QMouseEvent>
#include <QPoint>
#include "ui_launcher.h"

class launcher : public QMainWindow {
    Q_OBJECT

public:
    launcher(QWidget* parent = Q_NULLPTR);

private:
    Ui::launcherClass ui;
    void mousePressEvent(QMouseEvent* eventVar);
    void mouseMoveEvent(QMouseEvent* eventVar);
    int mouseClickX = 0;
    int mouseClickY = 0;

};

launcher.cpp

#include "launcher.h"

launcher::launcher(QWidget* parent) : QMainWindow(parent) {
    ui.setupUi(this);
}


void launcher::mousePressEvent(QMouseEvent* eventVar) {

    mouseClickX = eventVar->x();
    mouseClickY = eventVar->y();
}

void launcher::mouseMoveEvent(QMouseEvent* eventVar) {
    move(eventVar->globalX() - mouseClickX, eventVar->globalY() - mouseClickY);
}

Louis Bernard
  • 229
  • 4
  • 20

3 Answers3

1

Your description isn't really clear. One should not be using a QMainWindow for a logon/in dialog. Having said that I created an application on Ubuntu 20.04 (should build fine for you as I used qmake). You can download the project zip here. When the application starts it looks like this:

enter image description here

After clicking on "golden" it looks like this:

enter image description here

After Green it looks like this:

enter image description here

After clicking on Freaky it looks like this:

enter image description here

Please note that FramelessWindowHint not only removes the title bar and system menu along with window frame, it also removes your ability to resize/drag/move the window.

My apologies for not taking out the StackOver1.pro.user file. Didn't think about it until just now. You will need to delete that or it could hose your build.

user3450148
  • 851
  • 5
  • 13
  • Thank you, I was able to figure it out using your answer! I'm new to GUI development, so may I ask why it's not good to use QMainWindow for login? I wanted to use `stackedWidget` to switch between pages on this window. – Louis Bernard Sep 05 '21 at 19:15
  • 1
    Set yourself up a Ubuntu 20.04 VM under Oracle VirtualBox. Get Qt and PostgreSQL installed for development. Build and test source code for this project: https://sourceforge.net/projects/xpnsqt/ – user3450148 Sep 05 '21 at 19:33
0
QPalette and QStyle for Border

Palette Can Change window styles and colors of the Application. and for Reference https://doc.qt.io/archives/qt-5.7/qtwidgets-widgets-styles-example.html

tamil
  • 99
  • 8
0

You can do something like this

self.setWindowTitle("‎") # Python

mainWindow.setWindowTitle(""); # C/C++

but instead of passing an empty string, pass an empty character. This one worked for me: https://emptycharacter.com/

Martí Climent
  • 407
  • 4
  • 9