1

I want set MainWindow title in two lines, like:

WINDOW
TRACKER

I tried to use :

this->setWindowTitle("WINDOW \nTRACKER");

but the result was WINDOW TRACKER in one line.

Any way is it possible to do it?

Thanks!

Sergiy Shvets
  • 180
  • 2
  • 14
  • 2
    `\n` is the escape sequence, but I doubt it'll work. Have you ever seen a multi-line window title? – LogicStuff Sep 29 '16 at 12:43
  • 1
    my designer gave me mockup with dual-line title, so i want to know is it possible to do it) – Sergiy Shvets Sep 29 '16 at 12:45
  • probably with some deriving of some classes but not by default I assume – Hayt Sep 29 '16 at 12:47
  • 1
    maybe you get some useful information here: https://forum.qt.io/topic/26108/customize-window-frame/6 – Hayt Sep 29 '16 at 12:48
  • 1
    Even if you are able to set multi line title, you will need to increase the height of title also. You will have to create a custom window for that. – Tushar Sep 29 '16 at 12:54
  • 1
    You would need a window manager that is willing to use a multi-line title. So your problem lies outside of Qt, really. – Toby Speight Sep 29 '16 at 13:28

2 Answers2

3

The titlebar text layout is mostly besides Qt's control, typically Qt just passes its caption straight to the window manager, and most window managers (including the one of Windows) don't support multiline text in the window caption.

If you want to do this kind of customization in a reliable way, you should create a borderless window and draw your own window decoration (the title bar, the window border, ...), handle all the relevant events (dragging on your "fake title bar" area should move the window, clicking on your "fake maximize" button should maximize the window, ...) and so on; it is definitely possible and gives you full control on everything, but it's quite tedious, and, most importantly, makes your application look completely foreign to the environment it's running in.

In short, I'd just avoid it.

Community
  • 1
  • 1
Matteo Italia
  • 123,740
  • 17
  • 206
  • 299
1

What you are wanting to do is possible by creating a QString and telling setWindowTitle to use it like this.

QString windowTitle("WINDOW \n TRACKER);
this->setWindowTitle(windowTitle);

There's one problem though as was already mentioned in a comment by @Tusher. The size of the top bar containing the window title isn't large enough to contain two lines of text. Unfortunately, QMainWindow does not support or offer the option of a two-lined window title. The code above produces the following ugly result.

enter image description here

  • 1
    `is possible` in your case. With most window managers it won't work. I don't see any other option other than client side decoration like most Gnome applications do nowadays. – HeyYO Sep 29 '16 at 13:56
  • Thanks) but this code working on linux but not on windows, i dont know why)) – Sergiy Shvets Sep 29 '16 at 13:58
  • 2
    That's because the Windows window manager doesn't support multi-line window titles. Sorry! – WhackinMyKeyboard Sep 29 '16 at 14:05