views:

306

answers:

2

I am puting a QWidget and a QTabWidget next to each other in one horisontal splitter. And the splitter loses it's shape, you can know that there is a splitter only by hovering mouse on it. How to make it visible?

Thanks.

+1  A: 

This is true for every splitter at least with WinXP and the default Luna thema (changing to classic solves the problem). If you want to stay with Luna you may change the way the splitters are rendered, e.g. by changing the background color of the handle.

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

    QApplication a(argc, argv);
    a.setStyleSheet("QSplitter::handle { background-color: gray }");
    MainWindow w;
    w.show();
    return a.exec();
}

You may find more on Qt style sheets at http://doc.trolltech.com/4.6/stylesheet-reference.html

merula
Thanks. This changes color but I would like to change the splitter relief. Is that possible?
Narek
The default behavior of splitter under windows is to draw background color. This is bad when the splitted components have bg-color too by default (QWidget). The windows way is to give them a different color and/or a sunken border (QFrame supports borders). If you want to use relief you have to change the style (forget about style sheet). Use setStyle() to change the style. Reliefs is supported e.g. by QPlastiqueStyle. You may apply setStyle() to the QApplication object or only to the splitter (not preferred).I would propose the native solution mentioned first.
merula
+3  A: 

Since the QSplitterHandle (which is what most people think of as the 'splitter') is derived from QWidget, you can add other widgets to it. Here is what I have done to solve this exact problem in the past:

// Now add the line to the splitter handle
// Note: index 0 handle is always hidden, index 1 is between the two widgets
QSplitterHandle *handle = pSplitter->handle(1);
QVBoxLayout *layout = new QVBoxLayout(handle);
layout->setSpacing(0);
layout->setMargin(0);

QFrame *line = new QFrame(handle);
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
layout->addWidget(line);

This adds a sunken line to the splitter handle. You can, of course, choose another style for the frame line or use something entirely different as the widget you add to the splitter handle.

David Walthall
Thank you so much :)!
Narek