Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Set palette for toolbar in MainWindow
QtWS25 Last Chance

Set palette for toolbar in MainWindow

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    matilly
    wrote on last edited by
    #1

    Hello,

    I want to set a palette for the toolbar of my QMainWindow and I don't see why it is not working, I hope someone here can help me :) !

    Here is my code (QT5)-:

    @#include "Mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
    {
    Fenetrep *zoneCentrale = new Fenetrep;

    // Bouton de retour a la page precedente
    QPixmap imagePrec;
    QPushButton *vignettePrec = new QPushButton ();
    imagePrec.load("precedent.png");
    QIcon ButtonIconPrec(imagePrec);
    vignettePrec->setIcon(ButtonIconPrec);
    vignettePrec->setIconSize(QSize(105,105));
    
    // Bouton de retour a l'accueil
     QPixmap imageAccueil;
     QPushButton *vignetteAccueil = new QPushButton ();
     imageAccueil.load("home.png");
     QIcon ButtonIconAccueil(imageAccueil);
     vignetteAccueil->setIcon(ButtonIconAccueil);
     vignetteAccueil->setIconSize(QSize(105,105));
    
     //Titre de la fenetre
     QFont f( "Arial", 15, QFont::Bold);
     QLabel *titre = new QLabel("<font color=\"#FFFFFF\">Bienvenue sur EDAI !</font>");
     titre->setFont(f);
    
    // Création de la barre d'outils avec les deux boutons et le titre (à passer en parametre)
    QToolBar *toolBarFichier = addToolBar("Fichier");
    toolBarFichier->addWidget(vignettePrec);
    QWidget *spacerWidget = new QWidget(this);
    spacerWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    spacerWidget->setVisible(true);
    QWidget *spacerWidget2 = new QWidget(this);
    spacerWidget2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    spacerWidget2->setVisible(true);
    toolBarFichier->addWidget(spacerWidget);
    toolBarFichier->addWidget(titre);
    toolBarFichier->addWidget(spacerWidget2);
    toolBarFichier->addWidget(vignetteAccueil);
    
    //Style de la barre d'outils <--------------------------------------------------------------------------------Not Working ?
    QPalette Pal;
    QLinearGradient linearGradientOutils(QPointF(0, 0), QPointF(0, 110));
    linearGradientOutils.setColorAt(0, Qt::blue);
    linearGradientOutils.setColorAt(0.5, Qt::darkBlue);
    linearGradientOutils.setColorAt(1, Qt::blue);
    Pal.setBrush(QPalette::Window,*(new QBrush(linearGradientOutils)));
    toolBarFichier->setAutoFillBackground(true);
    toolBarFichier->setPalette(Pal);
    
    
    connect(vignettePrec, SIGNAL(clicked()), qApp, SLOT(quit()));
    
    setCentralWidget(zoneCentrale);
    setWindowState(this->windowState() ^ Qt::WindowMaximized);--
    

    }@

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      Have you tried using a lineargradient element in a qss stylesheet applied to the toolbar? I haven't tried it myself, but it may work for you.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        matilly
        wrote on last edited by
        #3

        Thanks it seems to be working with stylesheet !
        While you are here, my other problem is that the palette of the central widget does not show when it is in the QMainWIndow but is working separately in the widget Fenetrep (defined in the beginning) ?

        I will try to use a stylesheet also but if it is another problem...

        1 Reply Last reply
        0
        • C Offline
          C Offline
          clochydd
          wrote on last edited by
          #4

          Just to understand your problem:
          You made zoneCentral the central Widget and cannot access the palette of zoneCentral even if you select it in the object tree?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            matilly
            wrote on last edited by
            #5

            The problem is that when I display the main window, only a part of the stylesheet of the central widget (defined the constructor of Fenetrep-) is displayed.
            The main Window :
            !http://img15.hostingpics.net/pics/936078mainwindow.png(MainWindow)!
            The widget display on its own : --
            !http://img15.hostingpics.net/pics/806282centralwidget.png(QWidget)!

            1 Reply Last reply
            0
            • C Offline
              C Offline
              clochydd
              wrote on last edited by
              #6

              I see - probably this is related to parent/child connection.
              Your stylesheet will be inherited to all children unless changed on child's layer

              1 Reply Last reply
              0
              • M Offline
                M Offline
                matilly
                wrote on last edited by
                #7

                Ok, I will look into that then, thanks !

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved