Re: QFrame MousePressedEvent
Code:
if (ui->REDbtn->isChecked())
{
ui->box_0_0->mousePressEvent(setStyleSheet("background-color: rgb(255,0,0)"));
}
what is this code supposed to do?
mousePressEvent is an event handler, do you know what that means?
Have you looked at the mousePressEvent() doc, to see which parameters it takes?
mousePressEvent() is not supposed to be called like that directly.
Re: QFrame MousePressedEvent
i have and im lost on what im suppose to do it seems that i have to make mousePressEvent a void function and that works but i want it to be able to click on a box and if red button is checked make that box red.
Code:
{
QFrame *frm
= findChild<QFrame
*>
(QString("box_%2_%2").
arg(event
));
if (frm)
{
frm->setStyleSheet("background-color: rgb(255,0,0)");
}
}
Re: QFrame MousePressedEvent
Look, what you have said so far, and your code, suggest you don't know C++.
C++ basic topics are off topic for this forum.
Re: QFrame MousePressedEvent
I do know C++! although i did not take a class on c++, its all self thought. If my labelling of things is wrong let me know. Don't assume i don't know some thing, i have gotten his far with QT and have made some fun useless apps. look here is my hole project in a zip. help me out don't bash. LED_Matrix.zip
Re: QFrame MousePressedEvent
Consider putting your frames in a QTableWidget. It would simplify your code.
Something like:
Code:
...
for(int row=0;row<10;++row)
for(int col=0;col<10;++col){
frame->setMaximumSize(50,50);
frame->setMinimumSize(50,50);
frame->setStyleSheet(//set color, corner radius etc//);
tableWidget->setCellWidget(row,col,frame);
}
tableWidget->resizeColumnsToContents();
tableWidget->resizeRowsToContents();
connect(tableWidget,SIGNAL(cellClicked(int,int)),this,SLOT(yourSlot(int,int)));
...
Then in the slot change the color of the frame in the appropriate cell, according to which color button is checked, with QTableWidget->cellWidget(int, int). As an aside, a QComboBox might work better than QPushButtons for color selection.
There might be a way to change all of the cells to the same color using style sheets but I think you will have to iterate over them to change the color.
Re: QFrame MousePressedEvent
use QButtonGroup....
And color button has a id.
QButtonGroup::addButton ( QAbstractButton * button, int id )
connect(buttonGroup, SIGNAL(buttonClicked ( int id )), frame, SLOT(setId(int id)));
In your QFrame subclass, you can add a member int id
void matrix::setId(int id)
{
this->id = id;
}
void matrix::mousePressEvent(QMouseEvent *event)
{
switch(id)
{
case 0: set red; break;
case 1: set blue; break;
.....
}
}