1

My initial problem was to make QDockWidget title bold. I tried this and it worked:

myDock->setStyleSheet("QDockWidget { font: bold }");

But I can't understand why the following code doesn't work:

myDock->setStyleSheet("QDockWidget::title { font: bold }";

Even if I use more complicated style sheet, every parameter of it has effect except for font: bold:

myDock->setStyleSheet("QDockWidget::title { font: bold;
                                            text-align: left; 
                                            background: red; 
                                            padding-left: 30px; }");

What is the problem with QDockWidget::title font?

hank
  • 9,553
  • 3
  • 35
  • 50
  • 2
    It doesn't work that way, refer this question http://stackoverflow.com/questions/13012410/qdockwidgettitle-need-to-change-the-font-size – warunanc Nov 12 '12 at 03:46

4 Answers4

2

First of all, I dont know why the font does not work, I can only quess. I have a felling that the default title bar is similar to window titlebar which is almost impossible to style. I was searching through source code which widget is used for title bar but found nothing.. Here is some code, good luck.

I think that the style sheet does not support font changes. By default for everything derived from QWidget applies that parameters like background etc will allways work. Other stuff like font may or may not be implemented.

But why wont you make custom title bar? It can be anything bundled in QWidget.

QLabel *label = new QLabel("Header Text", myDock);
label->setStyleSheet("color: orange; font-size: 14pt; font-weight: bold;");
myDock->setWidget(bodyWidget);
myDock->setTitleBarWidget(label);

I've tested with Qt 5.3 it works, although there are missing buttons like close or undock :-/

I think that you can create them (with push button or so) and bundle everything in one widget, then set it with setTitleBarWidget and connect some signals. There is at least hide() slot for close button and you may have to code slot for float using setFloat.

nayana
  • 3,787
  • 3
  • 20
  • 51
1

QDockWidget *dock = new QDockWidget(); QFont curFont = dock->font(); curFont.setBold(true); dock->setFont(curFont);

alez
  • 69
  • 7
0

Specify it like this way

MyDock->setStyleSheet("QDockWidget::title { font: 75 11pt "Ubuntu";}");

where 75 is the parameter for bold, 11pt the size of your font and "Ubuntu" the type of your font.

ScarCode
  • 3,074
  • 3
  • 19
  • 32
  • I've tried `myDock->setStyleSheet("QDockWidget::title { font: 75 11pt \"Verdana\";}");` and it didn't work. – hank Jun 28 '12 at 10:55
-1

You're missing a semicolon (and a closing bracket?).

myDock->setStyleSheet("QDockWidget::title { font: bold; }");
i know nothing
  • 951
  • 1
  • 10
  • 27