Unsolved How to use one function to connect 10 QLabels?
-
Hello, I have 10 QLabels and I want to write context menus for them. But I found out that I need to write 10 connect functions. Is there a way to combine them so that I could write less?
-
Hi,
Make a vector of these labels and use a for loop with the connect statement in it.
-
You might want to check out QSignalMapper
-
@SGaist said in How to use one function to connect 10 QLabels?:
Make a vector of these labels and use a for loop with the connect statement in it.
You can even create it on the fly:
for(QLabel* singleLabel : {label1,label2,label3,label4}){ QObject::connect(singleLabel,&QLabel::customContextMenuRequested,/*etc*/); }