c++ - Adding a QLabel to a QWidget -


I am trying to add using. I am setting the label's text to something but it is not visible in the label.

Here is the code snippet:

  setStyleSheet ("QWidget {background-color: RGBA (160, 160, 160, 255); boundary-radius: 7px;} "); QLabel * label = new QLable (this); QHBoxLayout * layout = new QHBoxLayout (); Label-> Set text ("random string"); Layout & gt; AddWidget (label); SetLayout (layout);   

is for the stylesheet widget in which QLabel has been added.

The string is not displayed inside the "random string" label.

Please help.

Your code contains a typo, it is not QLabel , not QLable ...

Assuming this will inform you in the compilation of time, I do not know what the problem is, code you probably have with us your project

mynewwidget.h #ifndef MyNEWWIDGET_H #define MYNEWWIDGET_H #include & lt; QWidget & gt; Category MyNewWidget: Public QWidget {Q_OBJECT Public: Clear MyNewWidget (QWidget * parent = 0); }; #endif // MYNEWWIDGET_H

mynewwidget.cpp

  #include "mynewwidget.h" # include & lt; QHBoxLayout & gt; # Include & lt; QLabel & gt; MyNewWidget :: MyNewWidget (QWidget * parent): QWidget (guardian) {setStyleSheet ("QWidget {background-color: RGBA (160, 160, 160, 255); range-radius: 7px;}"); QLabel * label = new QLabel (this); QHBoxLayout * layout = new QHBoxLayout (); Label-> Set text ("random string"); Layout & gt; AddWidget (label); SetLayout (layout); }   

and the result is

http: / /i.imgur.com/G6OMHZX.png

Which I think is what you want ...

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -