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. Custom Checkbox
QtWS25 Last Chance

Custom Checkbox

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 465 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.
  • I Offline
    I Offline
    IknowQT
    wrote on last edited by VRonin
    #1

    ====================================
    Header

    class QCustomToggle : public QCheckBox
    {
    	Q_OBJECT
    public:
    	QCustomToggle(QWidget* parent = Q_NULLPTR);
    	~QCustomToggle();
    private:
    	Ui::QCustomToggle	ui;
    	QCheckBox*			m_pCheckbox;
    public slots:
    	void ClickedChecked();
    protected:
    	void	paintEvent(QPaintEvent* e);
    };
    

    cpp

    QCustomToggle::QCustomToggle(QWidget *parent)
    {
    	ui.setupUi(this);
    
    	m_pCheckbox = this;
    	this->setFixedSize(60, 28);
    	this->setCursor(Qt::PointingHandCursor);
    
    	this->connect(m_pCheckbox, SIGNAL(&QCheckBox::stateChanged(int)), this, SLOT(ClickedChecked()));
    }
    
    QCustomToggle::~QCustomToggle()
    {
    }
    
    void QCustomToggle::paintEvent(QPaintEvent* event)
    {
    	QPainter pPaint(this);
    	pPaint.setRenderHint(QPainter::Antialiasing);
    	pPaint.setPen(Qt::NoPen);
    
    	QColor bgcolor("#777");
    	QColor circlecolor("#DDD");
    	QColor activecolor("#00BCff");
    
    	QRect rect = QRect(0, 0, 60, 28);
    	pPaint.setBrush(bgcolor);
    	pPaint.drawRoundedRect(0, 0, rect.width(), 28, 28 / 2, 28 / 2);
    }
    
    
    void QCustomToggle::ClickedChecked()
    {
    
    }
    

    I'm trying to create a custom widget.
    So I inherited the checkbox, and when I clicked, I tried to signal a change in status, but no signal pops up.

    How can I send a status change signal?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      @IknowQT said in Custom Checkbox:

      this->connect(m_pCheckbox, SIGNAL(&QCheckBox::stateChanged(int)), this, SLOT(ClickedChecked()));

      This is wrong- there is no such signal "&QCheckBox::stateChanged(int))". connect() returns false (which you can check) and you will get a warning about this during runtime. Please read the documentation and better use the new signal/slot syntax.

      And please properly format your code with the code-tags for better readability.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      4

      • Login

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