QGroupBox + mousePress
Verfasst: 11. Januar 2010 18:05
Hallo,
Mal wieder sitze ich vor einem Problem, bei dem ich nicht weiter weiß.
Ich arbeite mit Qt4.5.1 und möchte eine QGroupBox mit einem Label drin. Das funktioniert, nur bekomme ich kein "mousePressEvent". Weiß jemand wieso und was ich tun muss, damit die GroupBox ein solches event empfangen kann?
Vielen Dank!
Mal wieder sitze ich vor einem Problem, bei dem ich nicht weiter weiß.
Ich arbeite mit Qt4.5.1 und möchte eine QGroupBox mit einem Label drin. Das funktioniert, nur bekomme ich kein "mousePressEvent". Weiß jemand wieso und was ich tun muss, damit die GroupBox ein solches event empfangen kann?
Code: Alles auswählen
class QtDragItem : public QWidget
{
Q_OBJECT
public:
QtDragItem(const QString &text, QWidget *parent = 0);
protected:
virtual void mousePressEvent(QMouseEvent *event);
private:
QHBoxLayout * m_layout;
QHBoxLayout * m_innerLayout;
QGroupBox * m_group;
QLabel * m_lblInfo;
};
QtDragItem::QtDragItem(const QString &text, QWidget *parent)
: QWidget(parent)
{
// create layout
m_layout = new QHBoxLayout(this);
m_layout->setSpacing(0);
m_layout->setContentsMargins(0,0,0,0);
// create groupbox
m_group = new QGroupBox(text);
// the inner layout for the groubox
m_innerLayout = new QHBoxLayout(m_group);
m_innerLayout->setSpacing(0);
m_innerLayout->setContentsMargins(6,8,6,6);
m_group->setAlignment(Qt::AlignHCenter);
m_group->setFocusPolicy(Qt::ClickFocus);
// the info label
m_lblInfo = new QLabel(text, this);
m_innerLayout->addWidget(m_lblInfo);
m_group->setLayout(m_innerLayout);
m_layout->addWidget(m_group);
}
void QtDragItem::mousePressEvent(QMouseEvent *event)
{
event->accept();
}