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. QPushButton text, icon and stylesheets
Forum Updated to NodeBB v4.3 + New Features

QPushButton text, icon and stylesheets

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 581 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.
  • G Offline
    G Offline
    goldstar2154
    wrote on last edited by
    #1

    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

    jsulmJ 1 Reply Last reply
    0
    • G goldstar2154

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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
      1

      • Login

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