Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QPushButton text, icon and stylesheets

    General and Desktop
    2
    2
    451
    Loading More Posts
    • 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.
    • G
      goldstar2154 last edited by

      Hi there.

      I have my own class named IconButton.
      This class contains QLabel* as member.
      This method allow me very flexible interface with accessing button or label.
      Also i can use custom stylesheets for label and for button.

      Code part:

      class wIconButton : public QPushButton, public wWidget
      {
      	Q_OBJECT
      ...
      protected:
           ...
      	QLabel* m_overlay_label;
      };
      
      wIconButton::wIconButton(const QString& name)
      	: wWidget(name)
      	, m_sub(0)
      {
             ...
      	m_overlay_label = new QLabel(this);
      	m_overlay_label->setObjectName("l_blue_gr");
      	m_overlay_label->setText("test");
      }
      

      Button created with this class looks like:
      0_1525784845337_StereoControlCenter 2018-05-08 16.04.48.png

      So main question is:
      Can i draw button like mine without additional Qlabel object?
      (and without tons of code)

      What i need from button:
      Specify text position (bottom, top...)
      Specify text color (font size)
      Specify gradient to label

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @goldstar2154 last edited by

        @goldstar2154 Yes, you can draw, see http://doc.qt.io/qt-5/qwidget.html#paintEvent and http://doc.qt.io/qt-5/qpainter.html

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 1
        • First post
          Last post