Results 1 to 3 of 3

Thread: change each separator's property

  1. #1
    Join Date
    Nov 2011
    Location
    Karlsruhe, Germany
    Posts
    57
    Thanks
    10
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default change each separator's property

    is there any way to set the width and color of each separator in QToolBar?

    Qt Code:
    1. toolBar -> setStyleSheet("QToolBar::separator { background-color: red; width: 30; height: 30px; }");
    To copy to clipboard, switch view to plain text mode 

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

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

    Qt Code:
    1. QAction* separator1 = toolBar->addSeparator();
    2. separator1->setObjectName("separator1");
    3.  
    4. toolBar -> setStyleSheet("QToolBar::separator#separator1 { background-color: red; width: 30; height: 30px; }");
    To copy to clipboard, switch view to plain text mode 

    it has no effect though...

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: change each separator's property

    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.

  3. #3
    Join Date
    Nov 2011
    Location
    Karlsruhe, Germany
    Posts
    57
    Thanks
    10
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: change each separator's property

    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:

    Qt Code:
    1. QFrame* separator = new QFrame(this);
    2. separator -> setFrameShape(QFrame::VLine);
    3. separator -> setFrameShadow(QFrame::Plain);
    4. separator -> setContentsMargins(margin, 0, margin, 0);
    5. QPalette p = separator -> palette();
    6. p.setColor(QPalette::WindowText, Qt::gray);
    7. separator -> setPalette(p);
    8.  
    9. addWidget(separator);
    To copy to clipboard, switch view to plain text mode 

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

    Unbenannt.png

    is there any flags i need to setup?
    Last edited by cic; 3rd December 2013 at 10:14.

Similar Threads

  1. Change property of QInputDialog button
    By Raadush in forum Qt Programming
    Replies: 2
    Last Post: 11th July 2012, 12:50
  2. Replies: 1
    Last Post: 20th February 2012, 20:44
  3. Change Stylesheet Using Dynamic Property
    By stefanadelbert in forum Qt Programming
    Replies: 4
    Last Post: 26th August 2010, 07:48
  4. How to mark Property name in Q_PROPERTY for language change??
    By Ankitha Varsha in forum Qt Programming
    Replies: 7
    Last Post: 14th April 2010, 13:22
  5. Replies: 1
    Last Post: 18th February 2009, 08:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.