fs_tigre
24th April 2012, 16:27
Hi,
I'm currently working on a very basic application that basically grebs the inputs form
two lineEdits displays the result and creates rectanglular shapes when a button is clicked,the
output is based on the two inputs, for instnce if the inputs were 2 and 3 it would draw a 2x3 rectangle (then I duplicate this rectangle based on other factors).
This appliation is a MainWindow using a tabWidget that I created in Qt Creator, all of my buttons and lineEdits are sitting on top of the tabWidget, the problem I'm currently having is that when I draw my rectangles they are actually showing underneath the tabWidget, in other words everything is working except that the rectangular shapes are drawn underneath the tabWidget.
Here is the code that caluculates and draws the recatangles
void MainWindow::calculate()
{
// calculations here
{
//draw rectangles
void MainWindow::paintEvent(QPaintEvent *event)
{
QPainter painter( this);
QRect sheet (20, 20, 120,600);
QBrush brush1(Qt::black, Qt::SolidPattern);
painter.fillRect(sheet, brush1);
if(m_flag)
{
for (int i=0; i< 20; i++)
{
for(int j=0; j<20; j++)
{
QRect rec ((((partWidth+1)*i)+30), (((partLength+1)*j)+30), partWidth, partLength);
QBrush brush(Qt::green, Qt::SolidPattern);
painter.fillRect(rec, brush);
}
}
}
}
// draw rectangles when on_pushButton_Calculate is clicked
void MainWindow::on_pushButton_Calculate_clicked()
{
calculate();
m_flag = true;
update();
}
Is there a way to draw something on a tabWidget?
I know its hard to make a suggestion without actually seeing the whole code but I don't think somebody will want to see
my poor code, I'm actully learning both Qt and C++ at the same time.
Thanks a lot
I'm currently working on a very basic application that basically grebs the inputs form
two lineEdits displays the result and creates rectanglular shapes when a button is clicked,the
output is based on the two inputs, for instnce if the inputs were 2 and 3 it would draw a 2x3 rectangle (then I duplicate this rectangle based on other factors).
This appliation is a MainWindow using a tabWidget that I created in Qt Creator, all of my buttons and lineEdits are sitting on top of the tabWidget, the problem I'm currently having is that when I draw my rectangles they are actually showing underneath the tabWidget, in other words everything is working except that the rectangular shapes are drawn underneath the tabWidget.
Here is the code that caluculates and draws the recatangles
void MainWindow::calculate()
{
// calculations here
{
//draw rectangles
void MainWindow::paintEvent(QPaintEvent *event)
{
QPainter painter( this);
QRect sheet (20, 20, 120,600);
QBrush brush1(Qt::black, Qt::SolidPattern);
painter.fillRect(sheet, brush1);
if(m_flag)
{
for (int i=0; i< 20; i++)
{
for(int j=0; j<20; j++)
{
QRect rec ((((partWidth+1)*i)+30), (((partLength+1)*j)+30), partWidth, partLength);
QBrush brush(Qt::green, Qt::SolidPattern);
painter.fillRect(rec, brush);
}
}
}
}
// draw rectangles when on_pushButton_Calculate is clicked
void MainWindow::on_pushButton_Calculate_clicked()
{
calculate();
m_flag = true;
update();
}
Is there a way to draw something on a tabWidget?
I know its hard to make a suggestion without actually seeing the whole code but I don't think somebody will want to see
my poor code, I'm actully learning both Qt and C++ at the same time.
Thanks a lot