I want to add QToolButton inside the QLineEdit.
I want to clear the text of QLineEdit control on that button click.
For example how in google image:
I have looked :
This StackOverflow article
But still not solved my issue.
Thanks in Advance.
This behaviour is available as a direct property to QLineEdit since Qt 5.2:
https://qt-project.org/doc/qt-5/qlineedit.html#clearButtonEnabled-prop
QLineEdit *edit = new QLineEdit(this);
edit->setClearButtonEnabled(true);
You can add a custom QAction with your self-defined icons to the QLineEdit:
https://qt-project.org/doc/qt-5/qlineedit.html#addAction
QLineEdit *edit = new QLineEdit(this);
QAction *action =
edit->addAction(QIcon("/path/to/icon"), QLineEdit::ActionPosition::LeadingPosition);
connect(action, &QAction::triggered, this, &ThisObject::doSomething);
//Create QToolButton:
QToolButton *clearButton = new QToolButton(this);
QPixmap pixmap(":/new/AppResource/images/clear_button.png");
clearButton->setIcon(QIcon(pixmap));
clearButton->setIconSize(pixmap.size());
clearButton->setCursor(Qt::ArrowCursor);
clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
clearButton->hide();
Connect Signal-Slot:
connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateCloseButton(const QString&)));
Visible on Text Enter into serach box:
clearButton->setVisible(true);
Related
Developing a Firefox Add-on. Anyone can please help to figure out how to make a Panel transparent.
Here is the code to show a panel:
var panel = require("sdk/panel").Panel({
width: 570,
height: 250,
contentURL: require("sdk/self").data.url("test.html")
});
panel.show();
I found a solution, but it isn't pretty since sdk/panel.js doesn't seem to expose the raw Panel object in order to tweak/extend or compose a another Panel from the existing one.
Here goes:
(1) Get the source for sdk/panel.js here: panel.js (raw) or from within sdk folder found in your addon xpi.
(2) Add it to your addon package as a new file.
(3) Change the requires parameters of this cloned file (lines 16-24) so that they point to the correct location from your addon.
example:
change
const { validateOptions: valid } = require('./deprecated/api-utils');
to
const { validateOptions: valid } = require('sdk/deprecated/api-utils');
(4) Find line 137, and modify the variable css to your liking. Like so:
...
let css = [
".panel-inner-arrowcontent, .panel-arrowcontent {padding: 0;}", //original css rule
".panel-inner-arrowcontent, .panel-arrowcontent {opacity: 0.50; border-radius: 0.35in;}" //additional css rules: semi-transparent panel with rounded borders.
].join(" ");
...
(5) Use the modified version of panel.js instead of the one that came with the sdk.
That should be it. Like I said, it isn't particularly elegant.
Is there a way to add img src tag in programmatic for a dijit.form.button?
In declarative, we can do something like this :
<div dojoType="dijit.form.Button"><img src="images/img.png"/></div>
In this case, the dijit button is completely replace by the image.
If I try something like this, the image not replace button but appear in :
var button = new dijit.form.Button({
showLabel : false,
label : "Validate",
iconClass : "alphaIcon validateIcon",
})
Your help would be very appreciated.
Thanks in advance
I think your approach should be to do exactly what you did AND create custom css to modify the appearance.
myIconButton.dijitButton .dijitButtonNode {
border: 0;
background-image: none;
background-color: transparent;
box-shadow: none;
}
var button = ... // same as above
dojo.addClass(button.domNode, 'myIconButton');
To directly answer your question, you could create your own button widget with a custom template that only had the image source.
dojo.declare("MyIconButton", [Button], {
templateString: '<div><img src="${imageSrc}"></img></div>'
});
NOTE: I didn't test this approach and there may be other modifications that you would need in MyIconButton because the base Button class would be expecting other nodes in the template.
The following will do what you want
this.button1.attr('label','<img src="' + this.constants.packagePrefix + '/images/button1.gif"/>');
I found it here:
http://mail.dojotoolkit.org/pipermail/dojo-interest/2009-August/038353.html
I have been using a class with background-image for buttons. This really made it hard to dynamically set the image. So, I had success using this:
domStyle.set(myButton.iconNode, 'background-image', 'url(images/icon.png)');
The trick was using iconNode, rather than domNode or containerNode.
I put jQGrtid inside jQuery simple model dialog.
z-index of simple dialog is 950 so i changed the z-index of jqGrid edit/add/delete pupups greater that that because otherwise they appearing below simple modal.
.jqmID1 { z-index: 1000 !important; }
.jqmID2 { z-index: 1000 !important; }
.jqmID3 { z-index: 1000 !important; }
All was looking good but than if i click/close "edit" and than click/clase "add" and than back to "edit" jQGrid popup again displaying below simple modal.
Than i find out than each time .jqmIDn increasing the n value for each new opening popup so my fix working only for 3 first popups ant than when value getting increased .jqmID4 .jqmID5 .... in is not working
Is there anything i can do to fix that? should i change jQgrid.js somewhere?
UPDATE:
OK, as a solution to that I've found a way how to change z-index in simple modal instead, so i decrease it like that:
$("#myDiv").modal({
...
zIndex: 800,
...
});
If someone have any another ideas let me know
You can use zIndex property of the Add and Edit Dialog. See this and this answers for details.
Wonder if there is a way to change color for a label in Spark FormItem component. I tried this:
#namespace s "library://ns.adobe.com/flex/spark";
#namespace mx "library://ns.adobe.com/flex/mx";
s|FormItem s|Label#labelDisplay {
color: #333333;
background-color: #FFFFFF;
font-size: 30;
}
and all of the styles work great, except the font color, which stays black for some reason. I would greatly appreciate any help resolving this.
See the answer from Peter DeHaan on my question "Do we need the equivalent of "labelStyleName" property for Spark FormItem class?" http://forums.adobe.com/thread/759374?tstart=0 "Because the color and fontWeight are declared in the default Spark FormItem skin, I believe you will have to create a custom skin if you want to override those styles."
I am struggling to set an background image for an QPushButton. No Success till now. Following is my code.
appsWidget::appsWidget(QWidget *parent)
:QWidget(parent)
{
QPushButton *button1 = new QPushButton("SETTINGS",this);
QPushButton *button2 = new QPushButton("TEST",this);
QPushButton *button3 = new QPushButton("IE",this);
button1->setStyleSheet("background-image:url(config.png)"); -> No success
qDebug("appWidget initialized.");
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
layout->addWidget(button3);
this->setLayout(layout);
connect(button1,SIGNAL(clicked()),this,SLOT(setClickIndex1()));
connect(button2,SIGNAL(clicked()),this,SLOT(setClickIndex2()));
connect(button3,SIGNAL(clicked()),this,SLOT(setClickIndex3()));
}
The image I am using in the stylesheet is located in the same project folder.
Do anybody has any solution?
You have to set the flat attribute to true:
button1->setFlat(true);
You also have to set the autofillbackground -
button1->setAutoFillBackground(true);
You may want to look at QToolButton which doesn't require it to be flat in order to render an image. I'm using them in an app I'm writing at the moment and they look very nice:
m_showAddCommentButton = new QToolButton();
m_showAddCommentButton->setAutoFillBackground(true);
palette = m_showAddCommentButton->palette();
palette.setColor(QPalette::Button,QColor(82,110,166));
m_showAddCommentButton->setPalette(palette);
m_showAddCommentButton->setIcon(QIcon(":/uiImages/addComment_50_50.jpg"));
m_showAddCommentButton->setIconSize(QSize(40,40));
m_showAddCommentButton->setToolTip("Comment");
connect(m_showAddCommentButton, SIGNAL(clicked()),
manager, SLOT(showAddComment()));
hLayout->addWidget(m_showAddCommentButton,0);
(My image is stored as a resource)
Your css selector is not correct.
You should do something like:
button1->setStyleSheet("QPushButton{ background-image: url(config.png); }");
You can use brush as palette element to fill background for any widget, for QPushButton that works when button is flat.
QPixmap pixmap("image.jpg");
QPalette palette;
QPushButton *button= new QPushButton(this);
palette.setBrush(button->backgroundRole(), QBrush(pixmap));
button->setFlat(true);
button->setAutoFillBackground(true);
button->setPalette(palette);