I try to build a frameless window with a single text label with changing text depending on chosen language and a boarder around it. This window should always have the smallest possible size. Here's the simple code without any configurations I tried so far.
QMainWindow* clientIDDisplay = new QMainWindow(0, Qt::Window
| Qt::FramelessWindowHint
| Qt::WindowStaysOnTopHint);
QGroupBox* mainWidget = new QGroupBox(clientIDDisplay);
mainWidget->setStyleSheet(stylesheetGroupBox);
QLabel* labelClientID = new QLabel(clientIDDisplay);
labelClientID->setStyleSheet(stylesheetLabel);
labelClientID->setText("Client");
QHBoxLayout* mainLayout = new QHBoxLayout(clientIDDisplay);
mainLayout->addWidget(labelClientID);
mainWidget->setLayout(mainLayout);
clientIDDisplay->setCentralWidget(mainWidget);
clientIDDisplay->show();
This shows the window but it's not as small as it should be, ther's much space left.
Using setMinimumSize(0,0)
doesn't help.
I think I understand to use QSizePolicy
to resize widgets depending on each other in one layout, as explained in this post layout mechanism. But it's a single widget in a groupbox, don't know whitch widget causes the bigger size of this window.
Using setFixedSize()
, I'm able to get a smaller size, but I don't know a way to set the right size. width()
of the label is NOT the width of the shown text.
Can anyone please explain which configurations I have to set to get my minimalistic window? I'm sure I overlook something, but I'm stuck.