Haris
Haris

Reputation: 14053

Clickable Qlabel How to use inside Designer

I need to make Qlabel clickable, which basically I used to display images in my main window, by googling I found that I need to create a subclass for the Qlabel, according to this link https://wiki.qt.io/Make-a-QLabel-Clickable.

My question is how can use this custom class inside my UI designer, is it possible ? Or I have to manage this UI element by code only?

Any help will be appreciated..

Thanks Haris

Upvotes: 0

Views: 2639

Answers (3)

Amol Saindane
Amol Saindane

Reputation: 1598

Using your link provided, I made my main() as below :

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow *w = new MainWindow;
    ClickableLabel *MyLable = new ClickableLabel("Amol",w);
    MyLable->show();
    w->show();

    return a.exec();
}

Important point is, as you customize your widget you need to pass parent pointer to the Custom widget,that is MainWindow here. Once you customize widget you need to give all its attributes programatically. Please add respective .h and .cpp for ClickableLabelclass in your project. Hope this helps for you.

Upvotes: 1

Petri Pyöriä
Petri Pyöriä

Reputation: 171

I suppose that UI designer refers to the QT Creator...

You can promote standard QLabel to clickable label following way:

  1. Create ClickableLabel -class.

  2. Create standard QLabel -widget in the QT Creator.

  3. Click right mouse button on the top of the new QLabel-widget in the form editor and select "Promote to".

  4. Enter name of the earlier created ClickableLabel -class to the Promoted class name -field. The dialog fills automatically also header file -field based on the name of the class.

  5. Press Add-button.

  6. Select a new promoted class from the list and press "Promote" -button.

Now the QLabel-widget, created on the step 2, is actually ClickableLabel-object.

Upvotes: 1

jpo38
jpo38

Reputation: 21514

Inside Qt Desiger, you have to create a QLabel and then "promote" it to the ClickableLabel class.

To do so, right-click the QLAbel object instantiated in your widget, select "Promote widget..." and specify ClickableLabel class name and path to the header file defining it.

Note that, both header and source files for ClickableLabel must be part of your Qt project.

This should simply work!

Upvotes: 3

Related Questions