{
painter.
setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::darkGreen);
//painter.drawRect(1, 2, 6, 4); // This is may be very small to notice, and may also get blended onto your background, using something bigger
painter.drawRect(1, 2, 50, 50); // Added this
painter.setPen(Qt::darkGray);
painter.drawLine(2, 8, 6, 2); // This is may be very small to notice, and may also get blended onto your background, using something bigger
painter.drawLine(2, 8, 50, 50); // Added this
}
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
setStyleSheet("MainWindow {border-width: 4px; border-image:url('/Users/sandeep_hyd123/Qt sandy/first/photo.jpeg') 4 4 4 4 stretch stretch;}");
//MyWidget my_widget; // This will never work, as you are creating the widget on stack and it will be deleted as soon as you exit this function / constructor
MyWidget* my_widget = new MyWidget(); // You need to create the widget on heap so that it is persistent when you exit the function / constructor
//QWidget::setFixedSize ( 400, 400 ); //You can ignore this time being
//QMainWindow::setCentralWidget(&my_widget); // Has to be modified
setCentralWidget(my_widget); // Added this
//Note that the widget will appear on the top left corner
}
void MyWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::darkGreen);
//painter.drawRect(1, 2, 6, 4); // This is may be very small to notice, and may also get blended onto your background, using something bigger
painter.drawRect(1, 2, 50, 50); // Added this
painter.setPen(Qt::darkGray);
painter.drawLine(2, 8, 6, 2); // This is may be very small to notice, and may also get blended onto your background, using something bigger
painter.drawLine(2, 8, 50, 50); // Added this
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setStyleSheet("MainWindow {border-width: 4px; border-image:url('/Users/sandeep_hyd123/Qt sandy/first/photo.jpeg') 4 4 4 4 stretch stretch;}");
//MyWidget my_widget; // This will never work, as you are creating the widget on stack and it will be deleted as soon as you exit this function / constructor
MyWidget* my_widget = new MyWidget(); // You need to create the widget on heap so that it is persistent when you exit the function / constructor
//QWidget::setFixedSize ( 400, 400 ); //You can ignore this time being
//QMainWindow::setCentralWidget(&my_widget); // Has to be modified
setCentralWidget(my_widget); // Added this
//Note that the widget will appear on the top left corner
}
To copy to clipboard, switch view to plain text mode
Bookmarks