c++ - Putting a line on a QPushButton -
i creating program draws graphs; want able have button user can press choose line color , style. want able visually show current selection is.
currently, know can using 2 seperate widgets, qpush button, , widget make myself draws line across using qpen.
i turn these 2 widgets single widget. want widget pushable "button" user presses , can signal out of run routine sets new qpen.
is functionality built in? or need create new widget re-implements either qpushbutton or qactionbutton? or should make widget listens mouseclick events on , create signal slot there?
you use qlabel
, set style sheet, , use line on graph. use bounds of qgroupbox
define x , y axis.
maybe this:
yourqlabel.setstylesheet("qwidget {background-color: rgb(255, 0, 0); color:white; border: 1px solid black;}"); // red black border
then can set height, width , position of qlabel
based on values graph. of course work if lines on graphs rectangular. if aren't, you'll have use other qlabel
.
use setgeometry method of qlabel
set this.
yourqlabel.setgeometry(x, y, width, height);
as far button, can similar if want. qpushbutton
has setgeometry
, setstylesheet
methods.
if want tell button on click, assuming have qpushbutton
object called mybutton
, add header file (.h):
class yourclass { q_object //... private slots: void on_mybutton_clicked(); }
then in source file (.cpp):
void yourclass::on_mybutton_clicked() { // stuff button on click }