#ifndef _S_RADIO_BUTTON_TABLE_ITEM_H_
#define _S_RADIO_BUTTON_TABLE_ITEM_H_
#include <qtable.h>
class SRadioButtonTableItem;
class STable : public QTable
{
Q_OBJECT
public:
STable
(int row,
int col,
QWidget *parent
= 0,
const char *name
= 0);
~STable();
SRadioButtonTableItem *item(int, int);
public slots:
void doValueChanged();
void clicked(int, int);
};
class SRadioButtonTableItem : public QTableItem
{
public:
SRadioButtonTableItem
(STable
*table,
const QString &text
);
virtual ~SRadioButtonTableItem();
bool isChecked() const { return m_bChecked; }
bool isBold() const { return m_bBold; }
void setChecked(bool check) { m_bChecked = check; }
void setBold (bool boldToggle) { m_bBold = boldToggle; }
protected:
virtual QWidget *createEditor
() const;
virtual void setContentFromEditor
( QWidget * w
);
virtual void paint
(QPainter *p,
const QColorGroup
&cg,
const QRect &cr,
bool selected
);
private:
bool m_bBold;
bool m_bChecked;
};
#endif
#ifndef _S_RADIO_BUTTON_TABLE_ITEM_H_
#define _S_RADIO_BUTTON_TABLE_ITEM_H_
#include <qtable.h>
class SRadioButtonTableItem;
class STable : public QTable
{
Q_OBJECT
public:
STable(int row, int col, QWidget *parent = 0, const char *name = 0);
~STable();
SRadioButtonTableItem *item(int, int);
public slots:
void doValueChanged();
void clicked(int, int);
};
class SRadioButtonTableItem : public QTableItem
{
public:
SRadioButtonTableItem(STable *table, const QString &text);
virtual ~SRadioButtonTableItem();
bool isChecked() const { return m_bChecked; }
bool isBold() const { return m_bBold; }
void setChecked(bool check) { m_bChecked = check; }
void setBold (bool boldToggle) { m_bBold = boldToggle; }
protected:
virtual QWidget *createEditor() const;
virtual void setContentFromEditor ( QWidget * w );
virtual void paint (QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected);
private:
const QString m_string;
bool m_bBold;
bool m_bChecked;
};
#endif
To copy to clipboard, switch view to plain text mode
#include <qradiobutton.h>
#include <qmessagebox.h>
#include <qcolor.h>
#include <qpainter.h>
#include <assert.h>
#include "sradiobuttontableitem.h"
STable
::STable(int row,
int col,
QWidget *parent,
const char *name
) : QTable(row, col, parent, name) {
QObject::connect(this,
SIGNAL(valueChanged
(int,
int)),
this,
SLOT(clicked
(int,
int)));
}
void STable::clicked(int row, int col)
{
if(item(row, col)->isChecked()) {
} else {
}
}
SRadioButtonTableItem* STable::item(int row, int col)
{
SRadioButtonTableItem *ti = (SRadioButtonTableItem *)QTable::item(row,col);
return ti;
}
STable::~STable() {
}
void STable::doValueChanged() {
emit valueChanged(currentRow(), currentColumn());
}
SRadioButtonTableItem
::SRadioButtonTableItem(STable
*table,
const QString &text
) : QTableItem( table, QTableItem::WhenCurrent, text ),
m_string(text),
m_bBold(FALSE),
m_bChecked(FALSE) {
setReplaceable( false );
}
SRadioButtonTableItem::~SRadioButtonTableItem() {
}
QWidget* SRadioButtonTableItem
::createEditor() const { STable *_table = static_cast<STable*>(table());
QObject::connect(editorWidget,
SIGNAL(clicked
()), _table,
SLOT(doValueChanged
()));
return editorWidget;
}
void SRadioButtonTableItem
::setContentFromEditor ( QWidget * w
) {
if ( w )
{
m_bChecked = TRUE;
} else {
m_bChecked = FALSE;
}
}
}
void SRadioButtonTableItem
::paint (QPainter *p,
const QColorGroup
&cg,
const QRect &cr,
bool selected
) {
f.setBold (m_bBold);
p->setFont (f);
QTableItem::paint (p, cg, cr, selected);
}
#include <qradiobutton.h>
#include <qmessagebox.h>
#include <qcolor.h>
#include <qpainter.h>
#include <assert.h>
#include "sradiobuttontableitem.h"
STable::STable(int row, int col, QWidget *parent, const char *name)
: QTable(row, col, parent, name) {
QObject::connect(this, SIGNAL(valueChanged(int, int)), this, SLOT(clicked(int, int)));
}
void STable::clicked(int row, int col)
{
if(item(row, col)->isChecked()) {
QMessageBox::information(this, 0, "TRUE");
} else {
QMessageBox::information(this, 0, "FLASE");
}
}
SRadioButtonTableItem* STable::item(int row, int col)
{
SRadioButtonTableItem *ti = (SRadioButtonTableItem *)QTable::item(row,col);
return ti;
}
STable::~STable() {
}
void STable::doValueChanged() {
emit valueChanged(currentRow(), currentColumn());
}
SRadioButtonTableItem::SRadioButtonTableItem(STable *table, const QString &text)
: QTableItem( table, QTableItem::WhenCurrent, text ),
m_string(text),
m_bBold(FALSE),
m_bChecked(FALSE) {
setReplaceable( false );
}
SRadioButtonTableItem::~SRadioButtonTableItem() {
}
QWidget* SRadioButtonTableItem::createEditor() const {
QWidget* editorWidget;
STable *_table = static_cast<STable*>(table());
editorWidget = new QRadioButton(table()->viewport() );
((QRadioButton*)editorWidget)->setText( text() );
QObject::connect(editorWidget, SIGNAL(clicked()), _table, SLOT(doValueChanged()));
return editorWidget;
}
void SRadioButtonTableItem::setContentFromEditor ( QWidget * w )
{
if ( w )
{
((QRadioButton*)w)->show();
if(((QRadioButton*)w)->isChecked()) {
m_bChecked = TRUE;
} else {
m_bChecked = FALSE;
}
}
}
void SRadioButtonTableItem::paint (QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected)
{
QFont f = p->font();
f.setBold (m_bBold);
p->setFont (f);
QTableItem::paint (p, cg, cr, selected);
}
To copy to clipboard, switch view to plain text mode
#include <qapplication.h>
#include <qstring.h>
#include <qtable.h>
#include "sradiobuttontableitem.h"
int main(int argc, char **argv)
{
STable *table = new STable(3, 3);
for(int row = 0; row < 3; ++row) {
for(int col = 0; col < 3; ++col) {
table->setItem(row, col, new SRadioButtonTableItem(table, str));
}
}
qApp.setMainWidget(table);
table->show();
qApp.connect(&qApp, SIGNAL(lastWindowClosed()), &qApp, SLOT(quit()));
return qApp.exec();
}
#include <qapplication.h>
#include <qstring.h>
#include <qtable.h>
#include "sradiobuttontableitem.h"
int main(int argc, char **argv)
{
QApplication qApp(argc, argv);
STable *table = new STable(3, 3);
for(int row = 0; row < 3; ++row) {
for(int col = 0; col < 3; ++col) {
QString str = "TEST";
table->setItem(row, col, new SRadioButtonTableItem(table, str));
}
}
qApp.setMainWidget(table);
table->show();
qApp.connect(&qApp, SIGNAL(lastWindowClosed()), &qApp, SLOT(quit()));
return qApp.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks