سؤال

My class uses QWidget and I've got some QPushButtons there and I'd like to set a QLabel on top of each button, which are set on the window by move() but QLabel doesn't want to move... I use setMargin but it moves it from left to right, but not up or down. There's an example of my code:

    self.btn = QPushButton(QIcon(),"Show table", self)
    self.btn.move(360, 10)
    self.btn.resize(100, 20)
    self.btn.clicked.connect(self.doAction)

    self.label = QLabel("Here comes the boom")

    layout_LineEdit = QVBoxLayout()
    layout_LineEdit.addWidget(self.label)
    self.setLayout(layout_LineEdit)
هل كانت مفيدة؟

المحلول

Add a moveEvent to your class and connect move signal to your slot, your slot should be a function that change your widget's geometry via:

YourClass::moveEvent(QMoveEvent *ev)
{ 
    emit move(ev->pos());
    QLabel::moveEvent(ev);
}

your SLOT function:

void move_label(QPoint *point)
{
    setGeomtry(0, 0, point->x, point->y);
}

and connect them as below:

connect(label_widget, SIGNAL(move(QPoint)), this, move_label(QPoint));
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top