PDA

View Full Version : Can't see frames around widgets



paie
10th August 2011, 09:48
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>

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




#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]);
}

norobro
10th August 2011, 19:22
"sunken" is not a valid border-style (http://doc.qt.nokia.com/4.7/stylesheet-reference.html#border-style).

paie
11th August 2011, 12:02
Thanks.

I can see the frames now, but I can't access the widgets inside them.

norobro
11th August 2011, 14:11
I think you can achieve the look that you want solely with style sheets:
bbStyle[0] = "color : black; background-color : #d3d3d3; min-height : 25; min-width : 75; "
"border-style: outset; font-weight : bold; border-width: 2 px; border-radius: 10 px; "
"border-color: #d3d3d3; ";Play around with the border-width & border-radius. Also try this:
bbStyle[1] = "BitButton{ color : black; background-color : #d3d3d3; min-height : 25; min-width : 75; "
"border-style: outset; font-weight : bold; border-width: 2 px; border-radius: 10 px; "
"border-color: darkgray;} "
"BitButton:hover { color : black; background-color: #54ff9f; border-color: #d3d3d3;}"
"BitButton:pressed{background-color:red}";