OK, here is what I'm trying to do.
I want a different frame around my pushbuttons than the one they come with. I have a subclass of QPushButton with the extras added, including their own frame. I'm thinking that I can superimpose a QFrame widget around the QPushButton and set the QFrame parameters as I choose.
Well, I just can't get the QFrames around the QPushButtons to appear.
The "parent" parameter is ui->centralWedget
What am I missing?
Here is the code, first the header, then the source. it's not large.
#ifndef BITBUTTON_H
#define BITBUTTON_H
#include <QtCore>
{
Q_OBJECT
public:
BitButton
(int number,
QWidget *parent
);
void bbToggle();
int bbId;
int bbState;
void setState(int state);
void setGeometry(QRect& rect);
signals:
void bbClicked();
private slots:
private:
};
#endif
#ifndef BITBUTTON_H
#define BITBUTTON_H
#include <QtCore>
class BitButton : public QPushButton
{
Q_OBJECT
public:
BitButton(int number, QWidget *parent);
void bbToggle();
int bbId;
int bbState;
void setState(int state);
void setGeometry(QRect& rect);
QFrame *frame;
signals:
void bbClicked();
private slots:
private:
QString bbStyle[2];
};
#endif
To copy to clipboard, switch view to plain text mode
#include <BitButton.h>
BitButton
::BitButton(int number,
QWidget *parent
){
bbId = number;
bbStyle[0] = "color: aqua; background-color: black;"
"border-style: sunken; border-width: 3px;"
"border-color: white;";
bbStyle[1] = "color: black; background-color: aqua";
frame->setLineWidth(3);
#ifdef Q_WS_WIN
font.setPointSize(font.pointSize()+2);
font.setFamily("Lucida Console");
#endif
#ifdef Q_WS_X11
font.setFamily("Monospace");
font.setPointSize(12);
#endif
this->setFont(font);
this->setState(0);
}
void BitButton
::setGeometry(QRect &rect
) {
rect.y()+2,
rect.width()+2,
rect.height()+2);
frame->setFrameRect(frameRect);
this->frame->show();
}
void BitButton::bbToggle()
{
this->setState(bbState ^= 1);
}
void BitButton::setState(int state)
{
bbState = state;
this
->setText
(QString::number(state
));
this->setStyleSheet(bbStyle[state]);
}
#include <BitButton.h>
BitButton::BitButton(int number, QWidget *parent)
: QPushButton(parent)
{
bbId = number;
bbStyle[0] = "color: aqua; background-color: black;"
"border-style: sunken; border-width: 3px;"
"border-color: white;";
bbStyle[1] = "color: black; background-color: aqua";
frame = new QFrame(parent);
frame->setFrameStyle(QFrame::Box | QFrame::Sunken);
frame->setLineWidth(3);
QFont font;
#ifdef Q_WS_WIN
font.setPointSize(font.pointSize()+2);
font.setFamily("Lucida Console");
#endif
#ifdef Q_WS_X11
font.setFamily("Monospace");
font.setPointSize(12);
#endif
this->setFont(font);
this->setState(0);
}
void BitButton::setGeometry(QRect &rect)
{
QRect frameRect = QRect(rect.x()+2,
rect.y()+2,
rect.width()+2,
rect.height()+2);
frame->setFrameRect(frameRect);
QPushButton::setGeometry(rect);
this->frame->show();
}
void BitButton::bbToggle()
{
this->setState(bbState ^= 1);
}
void BitButton::setState(int state)
{
bbState = state;
this->setText(QString::number(state));
this->setStyleSheet(bbStyle[state]);
}
To copy to clipboard, switch view to plain text mode
Bookmarks