0

I'm trying to change the colour of a couple of horizontal lines (the ones just above and below the horizontal toolbar) in a QMainWindow.

I would like to darken the colour of these lines

I'm using QPalette to change the colours of the main window, and am able to set most things I want. However, I'm not sure where to set the colour of these two horizontal grey lines.

Edit: The grey lines are definitely an element of the horizontal toolbar.

Code snippet:

    app = QApplication(sys.argv)
    app.setStyle("Fusion")
    wnd = IOMainWindow()


    palette = QPalette()

    #experimenting with colours
    palette.setColor(QPalette.Window, QColor('#21252b'))
    palette.setColor(QPalette.Highlight, QColor('#21252b'))
    palette.setColor(QPalette.WindowText, Qt.lightGray)
    palette.setColor(QPalette.Base, QColor('#1d2126'))
    palette.setColor(QPalette.AlternateBase, QColor('#333438'))
    palette.setColor(QPalette.ToolTipBase, Qt.white)
    palette.setColor(QPalette.ToolTipText, Qt.white)
    palette.setColor(QPalette.Text, Qt.lightGray)
    palette.setColor(QPalette.Button, QColor(53, 53, 53))
    palette.setColor(QPalette.ButtonText, Qt.lightGray)
    palette.setColor(QPalette.BrightText, Qt.red)
    palette.setColor(QPalette.Link, QColor(42, 130, 218))
    palette.setColor(QPalette.HighlightedText, Qt.white)

    app.setPalette(palette)
musicamante
  • 41,230
  • 6
  • 33
  • 58
  • 1
    I'm afraid that you can't, unless you also set a *full* stylesheet with the QToolBar selector (you cannot just set the border). Also note that you should not use the same color for ToolTipBase and ToolTipText. – musicamante Dec 09 '21 at 14:19
  • 1
    Thanks musicamante :) I was able to achieve what I wanted with `code` self.components_toolbar.setStyleSheet('QToolBar {border-bottom: 1px solid "#333841"; border-top: 1px solid "#333841";}') `code` ...though I do miss out on a nice one pixel indentation effect which was happening before. I wonder if that's controlled in the border style? Anyway, will play around more with it. Thanks! – user2407089 Dec 09 '21 at 15:30
  • Uhm, that's interesting: I tried it today and it didn't properly apply the stylesheet (the buttons became "unstyled"). Now I realize that the problem was related to the execution order: setting the palette *after* showing the main window doesn't properly propagate everything (style, stylesheet and palette). This makes my previous comment partially incorrect. I'll add an answer with further explanation about the topic. What do you mean by that "pixel indentation effect"? Can you clarify it, possibly by [edit]ing your question and provide a [mre] (and eventually screenshots)? – musicamante Dec 09 '21 at 20:32

0 Answers0