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");
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->setDisabled(true);
connect(Add,SIGNAL(clicked()),this,SLOT(addIN()));
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:
private slots:
void addIN()
{
emit addOUT(Date);
}
signals:
};
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);
};
To copy to clipboard, switch view to plain text mode
I am setting widget this way:
QTableCalendarWidget *Day=new QTableCalendarWidget(Items[i]->toolTip(),Ev,Bd);
Calendar->setCellWidget(Items[i]->row(),Items[i]->column(),Day);
QTableCalendarWidget *Day=new QTableCalendarWidget(Items[i]->toolTip(),Ev,Bd);
Calendar->setCellWidget(Items[i]->row(),Items[i]->column(),Day);
To copy to clipboard, switch view to plain text mode
Where Items[i] is QTableWidgetItem already added to QTableWidget, with date as a ToolTip.
The appearance:zrzut ekranu2.png
As all of you can see the custom widget is flat. Standard QTableWidgetItem is visible normally.
Bookmarks