Solved How can I print my QPushButton?
-
Hi, I'm using Qt5.5 on my computer.
Fist this is my codeIf it works correctly then my push button will turn to green or red.
But it didn't work right, it can't paint anything out.
There is no error.
So i assume that my code logic is correct.Is there anything that i miss to set?
Please help!
-
@victor-wang
something like this:
QPushButton{ background-color: blue; }
QPushButton:disabled{ background-color: yellow; }
QPushButton:pressed{ background-color: orange; }
QPushButton:focus:pressed{ background-color: black; }
QPushButton:focus{ background-color: green; }
QPushButton:hover{ background-color: red; }
QPushButton:checked{ background-color: pink; } -
@Taz742
You mean add those functions in?
Could you describe more detailed? -
Hope you got a chance to look at documentation
-
@dheerendra
I have no background-color on my computer.
Why is happening ? -
@victor-wang Not related to your question: why do you open /dev/sda1? Do you assume /dev/sda1 is USB device? It is most probably not. You should not use such hard coded devices in your code as they can vary even on same machine depending on which/how many devices are connected.
-
@jsulm
That because I don't know how to judge the place that if USB is in and will mount to where. -
@victor-wang It will not work this way. Qt does not provide functionality to detect a USB device. But you can use for example: http://libusb.org/
-
@jsulm
Thank you!
I will look at it later, first of all i have to solve current problem.
Do you know how to fix it?This is my current code now.
I write it like this.
QPalette pal = ui->pushButtonPT_USB_ResultLight1->palette(); pal.setColor(QPalette::Button,Qt::green); ui->pushButtonPT_USB_ResultLight1->setPallette(pal);
-
@victor-wang
like @dheerendra said, use StyleSheets://Instead of setPalette and repaint use: ui->pushButtonPT_USB_ResultLight1->setStyleSheet("QPushButton{background-color:red;}"); //and for the else ui->pushButtonPT_USB_ResultLight1->setStyleSheet("QPushButton{background-color:green;}");
PS:
you need better names for your variables.. -
Thank you!!!!!!!
It worked perfect!
thank you so much -
Hi,
Since you are using Qt, KDE's Solid framework might make thing simpler to detect USB mass storage devices.