PDA

View Full Version : change each separator's property



cic
2nd December 2013, 16:20
is there any way to set the width and color of each separator in QToolBar?



toolBar -> setStyleSheet("QToolBar::separator { background-color: red; width: 30; height: 30px; }");


e.g the code above can only set general seperator property.

Ive read some posts with possibly assigning an object name but failed.



QAction* separator1 = toolBar->addSeparator();
separator1->setObjectName("separator1");

toolBar -> setStyleSheet("QToolBar::separator#separator1 { background-color: red; width: 30; height: 30px; }");


it has no effect though...

d_stranz
3rd December 2013, 03:32
it has no effect though...

Of course not. A QAction is an abstraction of a command, not a user interface element. It holds properties (like text or icons) that can be used by actual GUI elements (like toolbar buttons or menu items) to render themselves, but the QAction itself is just class to hold all these things in a convenient place. Giving it an object name doesn't give it magical powers.

If the QToolBar class itself has no way to change the properties of individual separators, then you are stuck unless you want to write your own toolbar class derived from QToolBar. You will have to rewrite the paintEvent(), in particular the part that paints the separators. It probably will not be easy.

cic
3rd December 2013, 10:14
Ok, then seems that the separator property in toolbar can not be flexibly modified via stylesheet.

Added after 49 minutes:

i used a QFrame to do this trick:



QFrame* separator = new QFrame(this);
separator -> setFrameShape(QFrame::VLine);
separator -> setFrameShadow(QFrame::Plain);
separator -> setContentsMargins(margin, 0, margin, 0);
QPalette p = separator -> palette();
p.setColor(QPalette::WindowText, Qt::gray);
separator -> setPalette(p);

addWidget(separator);


but the color of the QFrame as vertical line didnt change.

9834

is there any flags i need to setup?