hey,
thanks for this fast answer.
I tried to creat an own QPushButton but it doesnt work. Maybe u can help me?
I tryed the following:
#ifndef SYMBOLBUTTON_H
#define SYMBOLBUTTON_H
#include <QWidget>
#include <QPushButton>
#include <QString>
{
Q_OBJECT
public:
int counter;
SymbolButton
(const QString
& text,
QWidget* parent
= NULL);
void changetext();
};
#endif // SYMBOLBUTTON_H
#ifndef SYMBOLBUTTON_H
#define SYMBOLBUTTON_H
#include <QWidget>
#include <QPushButton>
#include <QString>
class SymbolButton : public QPushButton
{
Q_OBJECT
public:
int counter;
SymbolButton(const QString& text, QWidget* parent = NULL);
void changetext();
};
#endif // SYMBOLBUTTON_H
To copy to clipboard, switch view to plain text mode
#include "symbolbutton.h"
#include <QMessageBox>
#include <QWidget>
#include <QPushButton>
SymbolButton
::SymbolButton(const QString
& text,
QWidget* parent
) : QPushButton(text,parent
){
connect(this,SIGNAL(clicked()),this,changetext());
}
void SymbolButton::changetext(){
this->counter++;
if ( this->counter>5)
this->counter=0;
setText("test");
}
#include "symbolbutton.h"
#include <QMessageBox>
#include <QWidget>
#include <QPushButton>
SymbolButton::SymbolButton(const QString& text, QWidget* parent) : QPushButton(text,parent)
{
connect(this,SIGNAL(clicked()),this,changetext());
}
void SymbolButton::changetext(){
this->counter++;
if ( this->counter>5)
this->counter=0;
setText("test");
}
To copy to clipboard, switch view to plain text mode
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QWidget>
#include <QPushButton>
#include "symbolbutton.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
SymbolButton *button = new SymbolButton;
ui->setupUi(this);
int rows = ui->gridLayout->rowCount();
int cols = ui->gridLayout->columnCount();
ui->gridLayout->addWidget(button,rows,cols,0);
}
MainWindow::~MainWindow()
{
delete ui;
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QWidget>
#include <QPushButton>
#include "symbolbutton.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
SymbolButton *button = new SymbolButton;
ui->setupUi(this);
int rows = ui->gridLayout->rowCount();
int cols = ui->gridLayout->columnCount();
ui->gridLayout->addWidget(button,rows,cols,0);
}
MainWindow::~MainWindow()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
This button should just change its text if u click on it and set counter = counter + 1.
Bookmarks