QLabel click event using Qt?

后端 未结 3 1123
无人共我
无人共我 2021-01-12 11:01

I\'m new in Qt and have a question.

I have QLabel and QLineEdit objects, and when QLabel text is clicked on, I want to set thi

3条回答
  •  清歌不尽
    2021-01-12 11:20

    Either style another type of QWidget such as a specific QPushButton to look like a QLabel and use its clicked() signal or inherit QLabel yourself and emit your own clicked() signal.

    See this example: https://wiki.qt.io/Clickable_QLabel

    If you choose the latter option you can pass the text in the signal. Then connect the necessary signals/slots up between the QLabel and the QLineEdit like so:

    QObject::connect(&label, SIGNAL(clicked(const QString& text)),
                     &lineEdit, SLOT(setText(const QString& text)));
    

提交回复
热议问题