How to set the shape of push button /tool button. ? say to oval or round shape
Thanks in advance
How to set the shape of push button /tool button. ? say to oval or round shape
Thanks in advance
Subclass and reimplement the paint event.
Another way is to write a new QStyle that styles only pushbuttons, and set set that style for the pushbuttons in question.
this is the way that I chose to subclass my buttons to get them to look like little green round "electrodes" in an electrode array
Qt Code:
{ grad.setColorAt(0.0, Qt::white); grad.setColorAt(0.1, Qt::green); grad.setColorAt(0.7, Qt::black); painter.setBrush(brush); painter.drawEllipse(2,2,20,20); }To copy to clipboard, switch view to plain text mode
ElectrodeButton is a subclass of QPushButton
MarkoSan (21st January 2008)
Is it possible to adapt button shape dynamically according to loaded icon? What I want to achieve is when button icon is loaded, it's size and shape is reset to size and shape of overlaping icon. How do I do it?
Qt 5.3 Opensource & Creator 3.1.2
It might be simplest to reimplement the paintEvent from the button. An alternative is to create a custom widget and provide an icon setting method that will also change the mask of the widget.
Ok, but how do I extract icon shape? For size, I can use QIcon::actualSize?
Qt 5.3 Opensource & Creator 3.1.2
MarkoSan (22nd January 2008)
Can you provide me with simple example, please?
Qt 5.3 Opensource & Creator 3.1.2
An example of what? Calling createHeuristicMask?
I did not get to step where I will use Calling createHeuristicMask yet. Right now, I have a big pixmap on disk (512x512) an when I set it in QPushButton it is so tiny it can be barely seen. I would like to resize it. How do I do that? I trided rescled, does not work. I tried to put some huge text near this pixmap in button, text is shown ok, pixmap is still tiny.
Shit, I've mixed up threads. I've posted new thread regarding how to resize icon in subclassed qpushbutton. Can you move it?
Qt 5.3 Opensource & Creator 3.1.2
It returns a mask which you should then pass to QWidget::setMask.
Well, this is what I've done:Qt Code:
{ // sets up button font m_ButtonFont.setFamily("1942 Report"); // sets font name m_ButtonFont.setPointSize(36); // sets font size m_ButtonFont.setBold(true); // sets bold on this->setFont(m_ButtonFont); // sets font // sets button palette (background and text color) this->setAutoFillBackground(true); // sets auto fill background feature m_ButtonPalette=this->palette(); // reads current palette this->setPalette(m_ButtonPalette); // sets modfied palette this->setFocusPolicy(Qt::NoFocus); // disables focus m_ButtonIcon.load(flagPicture); // creates new icon based on icon /* m_ButtonIcon.scaled(256, 256, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); // tries to resize icon */ setIcon(m_ButtonIcon); // sets icon setMask(m_ButtonIcon.createHeuristicMask()); // sets mask }To copy to clipboard, switch view to plain text mode
And the buttons are not drawn at all, neither are icons in buttons.
Last edited by MarkoSan; 22nd January 2008 at 00:27.
Qt 5.3 Opensource & Creator 3.1.2
Try reimplementing the paint event and draw the pixmap yourself if you can't handle this approach.
Hmm, there is no need for insulting me that I am incompetent, but I am doing this thing for the first time and I am really lost.
Qt 5.3 Opensource & Creator 3.1.2
Whoa!!!
Now it workd perfectly!!!
Here is working code:Qt Code:
{ // sets up button font m_ButtonFont.setFamily("1942 Report"); // sets font name m_ButtonFont.setPointSize(36); // sets font size m_ButtonFont.setBold(true); // sets bold on this->setFont(m_ButtonFont); // sets font // sets button palette (background and text color) this->setAutoFillBackground(true); // sets auto fill background feature m_ButtonPalette=this->palette(); // reads current palette this->setPalette(m_ButtonPalette); // sets modfied palette this->setFocusPolicy(Qt::NoFocus); // disables focus m_ButtonIcon.load(flagPicture); // creates new icon based on icon setIcon(m_ButtonIcon); // sets icon setMask(m_ButtonIcon.createHeuristicMask()); // sets mask }To copy to clipboard, switch view to plain text mode
Qt 5.3 Opensource & Creator 3.1.2
Dear MarkoSan!
Can I know without passing pParent into a QPushButon how a way your CFlagButton display?
When my button is appeared on the screen some of the blackish area appeared up & down corner of the push button?
Can you put your complete code for clear understanding or change in my code which I am attaching?
Qt Code:
#include<QtGui> class CFlagButton:QPushButton { public: { QFont m_ButtonFont; // sets up button font //m_ButtonFont.setFamily("1942 Report"); // sets font name m_ButtonFont.setPointSize(36); // sets font size m_ButtonFont.setBold(true); // sets bold on this->setFont(m_ButtonFont); // sets font // sets button palette (background and text color) this->setAutoFillBackground(true); // sets auto fill background feature QPalette m_ButtonPalette; m_ButtonPalette=this->palette();// reads current palette this->setPalette(m_ButtonPalette);//sets modfied palette this->setFocusPolicy(Qt::NoFocus);//disables focus QPixmap m_ButtonIcon; m_ButtonIcon.load(flagPicture);//creates new icon based on icon setIcon(m_ButtonIcon);//sets icon setMask(m_ButtonIcon.createHeuristicMask());//sets mask } }; int main (int argc, char **argv) { QWidget w; CFlagButton btn(&w,"plane.jpg"); w.show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
Anurag Shukla
A man who never makes mistake is the man who never does anything! Theodre Rosvelt!
I can show the code to you next thurdsay, until then I cannot ....
Qt 5.3 Opensource & Creator 3.1.2
Bookmarks