Unable to copy values of QLabel
-
One more question , I want to copy text next to checkbox in following code
QGroupBox* checkGroupBox = NULL;
QGroupBox* LabelGroupBox = NULL;
QGridLayout *checkGroupBoxLayout = NULL;
QGridLayout *labelGroupBoxLayout = NULL;int crow = 0, ccol = 0, lrow = 0, lcol = 0;
for (mymap<string,string>::iterator ni =tab.begin(); ni; ni++) {
string attrName = ni.object();
string attrValue = ni.value();if (attrValue == "true" || attrValue == "false") { if (!attrCheckGroupBox) { checkGroupBox = new QGroupBox(name); checkGroupBoxLayout = new QGridLayout; checkGroupBox->setLayout(attrCheckGroupBoxLayout); checkGroupBox->setEnabled(true); /* read only */ } QCheckBox* attrCheckBox = new QCheckBox((str_t)"attName"); attrCheckGroupBoxLayout->addWidget(attrCheckBox, crow, ccol); attrCheckBox->setChecked(attrValue == "true");
-
@Qt-Enthusiast said in Unable to copy values of QLabel:
Hi
"cop text next to checkbox "'
Sounds strange to me ?Do you mean , you want to create a new Label and sets it text and insert into the layout, next to the checkbox?
-
https://s30.postimg.org/m9i70o3dt/checkbox.png and I want to copy the value of text dont_use
-
@Qt-Enthusiast
Are you asking How to get text ?
checkbox->text() gives it -
No I should have pop up with Copy QAction and also should be able to select and copy and paste with Ctrl-C and Ctrl-V
-
@Qt-Enthusiast
So you want to add a context menu to it ?
Like edit has ?
I think you must create it yourself. -
Can u help
for coding and how to impliment CTRL +C and CTRL V -
@Qt-Enthusiast
It will be the same as any other menu using shortcuts etc.Maybe go look for some sample. I dont have any.
its not trivial to replicate the default context menu.
It will take some code.Maybe other have a better idea. I guess this has been asked before. so give it some time and see :)
I would look into
QLineEdit::createStandardContextMenu().maybe you can just hook it to the checkbox
-
Anu reference code for the same
-
@Qt-Enthusiast
https://forum.qt.io/topic/31233/how-to-create-a-custom-context-menu-for-qtableviewkey points being
setContextMenuPolicy(Qt::CustomContextMenu);
connect(table, SIGNAL(customContextMenuRequested(QPoint)),SLOT(customMenuRequested(QPoint))); -
Also, please dont RUSH over
QLineEdit::createStandardContextMenu().You be able to create it this way and then just connect the signals to your slots to copy
the text.I did not try this but it might save you time.