Erste Maus klicken Sie auf Standort ein label in qt

Habe ich gegoogelt um und fand dieser forum thread, in dem die OP zu haben scheint, hatte das genaue problem, das ich habe. Die Frage ist, wie würde ich Erben von QLabel und implementieren Sie die mousepressed-event? Ich vermute, es wäre so etwas wie dieses:

class CustomLabel : public QLabel
{
public:
    //what about the constructors?
    void mousePressEvent ( QMouseEvent * ev );
}

void CustomLabel::mousePressEvent ( QMouseEvent * ev )
{
    QPoint = ev->pos();
    //I want to have another function get the event position.
    //How would I achieve this? It's void!
    //Is there perhaps some way to set up a signal and slot with the position?
}

Und nachdem ich erfolgreich erstellt haben CustomLabel Klasse, wie würde ich in der Lage sein, um es in der Entwurfsansicht?

  • Hast du die zweite Lösung setzen Sie das Etikett wieder an das Hauptfenster?
Schreibe einen Kommentar