PDA

View Full Version : Custom item widgets are flat.



mkarol
6th May 2014, 22:18
I have a class which is custom widget for QTableWidgetItem. Using Qt 4.8 everything was OK, but in Qt 5.2.1 there is a problem.

My widget class:

class QTableCalendarWidget: public QWidget
{
Q_OBJECT
public:
QTableCalendarWidget(QString ToolTip,bool Ev,bool BDay)
{
Date=QDate::fromString(ToolTip,"d/MM/yyyy");
Event=new QLabel(this);
Birth=new QLabel(this);
Label=new QLabel(QString::number(Date.day()),this);
Add=new QPushButton(this);
QPixmap w=QPixmap(12,12);
w.fill(Qt::transparent);
if(Ev)
{
Event->setPixmap(QIcon(":/cal/Ev").pixmap(15));
}
else
{
Event->setPixmap(w);
}
if(BDay)
{
Birth->setPixmap(QIcon(":/cal/BDay").pixmap(15));
}
else
{
Birth->setPixmap(w);
}
Label->setAlignment(Qt::AlignHCenter);
Add->setStyleSheet("QPushButton {border: 0px solid white;}");
Add->setIcon(QIcon(w));
Add->setDisabled(true);
connect(Add,SIGNAL(clicked()),this,SLOT(addIN()));
QHBoxLayout *Layout=new QHBoxLayout();
Layout->setSpacing(1);
Layout->addWidget(Event);
Layout->addWidget(Birth);
Layout->addWidget(Label,Qt::AlignHCenter);
Layout->addWidget(Add);
this->setLayout(Layout);
}
void AddB()
{
Add->setEnabled(true);
Add->setIcon(QIcon(QIcon(":/main/Add").pixmap(12,12)));
}
private:
QDate Date;
QLabel *Event;
QLabel *Birth;
QLabel *Label;
QPushButton *Add;
private slots:
void addIN()
{
emit addOUT(Date);
}
signals:
void addOUT(QDate);
};

I am setting widget this way:

QTableCalendarWidget *Day=new QTableCalendarWidget(Items[i]->toolTip(),Ev,Bd);
Calendar->setCellWidget(Items[i]->row(),Items[i]->column(),Day);
Where Items[i] is QTableWidgetItem already added to QTableWidget, with date as a ToolTip.

The appearance:10339

As all of you can see the custom widget is flat. Standard QTableWidgetItem is visible normally.

ChrisW67
7th May 2014, 06:23
What do you mean by "the custom widget is flat"?

mkarol
7th May 2014, 16:00
The widget is 1 px high. In previous version widget height was a cell height. Is there any way of changing it without calling resize()? Resizing cause that text is out of cell.