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. Redraw text in custom widget removes button functionality (QPushbutton inherited) [SOLVED]
Forum Updated to NodeBB v4.3 + New Features

Redraw text in custom widget removes button functionality (QPushbutton inherited) [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.0k Views 1 Watching
  • 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
    ion_knight
    wrote on last edited by
    #1

    When deriving from QPushbutton all my QSS is applied as my paintevent is working. However when I insert my paintevent, Text is no longer drawn instead. Below is my paint event I use to draw the Push button however I am not sure if I am missing something to use this command on a derived QPushbutton.

    @void GUIButton::paintEvent(QPaintEvent* aEvent)
    {
    QStyleOption Opt;
    Opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget,&Opt,&p,this);
    }@

    Do I need to change the QStyle::PE_Widget to another QStyle ?

    1 Reply Last reply
    0
    • I Offline
      I Offline
      ion_knight
      wrote on last edited by
      #2

      Figure out my problem however have created another problem because of it instead of actually having a button the button has now completely disappeared below is a simple example to show the problem.

      custom_button.cpp

      @#include "custom_button.h"

      Custom_Button::Custom_Button(QWidget *parent) :
      QPushButton(parent)
      {
      }

      void Custom_Button::paintEvent(QPaintEvent* aEvent)
      {
      QStyleOption Opt;
      Opt.init(this);
      QPainter p(this);
      style()->drawPrimitive(QStyle::PE_PanelButtonCommand,&Opt,&p,this);
      style()->drawItemText(&p,this->rect(),Qt::AlignCenter,(this->palette()),true,this->text());
      }
      @

      custom_button.h
      @#ifndef CUSTOM_BUTTON_H
      #define CUSTOM_BUTTON_H

      #include <QPushButton>
      #include <QStyleOption>
      #include <QPainter>

      class Custom_Button : public QPushButton
      {
      Q_OBJECT
      public:
      explicit Custom_Button(QWidget *parent = 0);

      void paintEvent(QPaintEvent* aEvent);
      

      signals:

      public slots:

      };

      #endif // CUSTOM_BUTTON_H
      @

      MainWindow.cpp
      @#include "mainwindow.h"
      #include "ui_mainwindow.h"
      //#include "custom_button.h"

      MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
      {
      ui->setupUi(this);

      mainCustom_Button * Button = new Custom_Button();
      //QPushButton *Button = new QPushButton();
      QVBoxLayout * layout = new QVBoxLayout();
      layout->addWidget(Button);
      
      QWidget * CenterWidget = new QWidget();
      setCentralWidget(CenterWidget);
      centralWidget()->setLayout(layout);
      

      }

      MainWindow::~MainWindow()
      {
      delete ui;
      }
      @

      Everything else is just a standard project, now what I am seeing is that the button isn't actually being drawn at all. If anyone has any idea why this is happening that would be great.

      1 Reply Last reply
      0

      • Login

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