audrey
audrey

Reputation: 1

Customizing a QDockWidget in Qt without QtDesigner

(sry for my bad english but i'll give my best)

I currently try to customize the style of several QDockWidgets. The only solution i found via the Qt Documentation -> Style Sheet is setting a Stylesheet to the Object in the QtDesignerView by right MouseClick -> set Stylesheet and kinda hardcode (looking similar to css). Pityfully i do not use the QtDesigner but code the graphical stuff in the EditorView of QtCreator.

My Question now - is it possible to customize Widgets by normal Editor nicer than

widget.setObjectName("widget")

and then setting the stylesheet via the constructor like this:

this->setStyleSheet("QDockWidget#widget{ background-color: red;........}");

this works fine for brief PushButtons e.g. but putting together dozen lines as a String could not be the best solution could it? I would be glad about some hints because i cannot find much about that on the net, my cpp/Qt knownledge is not yet the best though :(

thanks

Upvotes: 0

Views: 2114

Answers (2)

yan bellavance
yan bellavance

Reputation: 4830

you call setStyleSheet from your program.

example:

pb->setStyleSheet(QApplication::translate("failoverCrit", "color: rgb(0, 0, 0);background-color: qlineargradient(spread:pad, x1:0.922018, y1:0.574, x2:0.385321, y2:0.159, stop:0 rgba(106, 106, 106, 255), stop:1 rgba(255, 255, 255, 255));", 0, QApplication::UnicodeUTF8));

example2:

ui.pbAssign->setStyleSheet(QString::fromUtf8("QPushButton {\n"
     "    border: 1px solid green;"
     "    border-radius: 3px;"
     "    padding: 4px;"
     "    background-color: qlineargradient(spread:pad, x1:1, y1:1, x2:1, y2:0, stop:0 rgb(255,255,153), stop:0.668182 rgba(255, 255, 255, 255));"
     " }\n"
     ""));

to remove the styling:

ui.pbAssign->setStyleSheet("");

Upvotes: 0

AJG85
AJG85

Reputation: 16197

This may not be the best solution but I'd probably do something along these lines:

  • Create the desired stylesheet in a .css file
  • Subclass QDockWidget
  • Add methods that use QFile to load/parse the .css file and set the styles etc
  • Then I might get fancy and do some things with QStyle and other related classes

Upvotes: 1

Related Questions