Unable to copy values of QLabel
-
mrjj Lifetime Qt Championreplied to Qt Enthusiast on 4 Feb 2017, 09:12 last edited by mrjj 2 Apr 2017, 09:15
@Qt-Enthusiast
Ok, so what is the issue then?
Just tested.
Even when disabled then
qDebug() << ui->textEdit->toPlainText();
still get the text.So What are you trying ? and what is not working ?
-
When its its enabled then I can get a POP up on right click and can copy as well I can copy ctrl-c and ctrv ,when it disabled then it does not come
So the requirement , we should not able to change the value of QLineEdit but at the same time we should be able to copy the value of the POp up menu
-
mrjj Lifetime Qt Championreplied to Qt Enthusiast on 4 Feb 2017, 09:29 last edited by mrjj 2 Apr 2017, 09:29
@Qt-Enthusiast
oK, you can NOT interact with it when disabled. so there can be no popups from clicking it.
Use myTextEdit->setReadOnly(true) instead. -
thanks that worked
-
@Qt-Enthusiast
Super. Remember to mark as Solved :) -
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 -
mrjj Lifetime Qt Championreplied to Qt Enthusiast on 4 Feb 2017, 10:47 last edited by mrjj 2 Apr 2017, 10:48
@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.
18/24