void map::resizeEvent(QResizeEvent *e){ int extraW = width() - minimumWidth(); int extraH = height() - minimumHeight(); btn_spb->setGeometry(100 + extraW, 145 + extraH, 120, 20); btn_msc->setGeometry(65 + extraW, 200 + extraH, 120, 20); btn_sev->setGeometry(0 + extraW, 230 + extraH, 120, 20); btn_kalin->setGeometry(20 + extraW, 110 + extraH, 120, 20); btn_murm->setGeometry(150 + extraW, 80 + extraH, 120, 20); btn_rost->setGeometry(45 + extraW, 260 + extraH, 120, 20); btn_ekb->setGeometry(210 + extraW, 260 + extraH, 120, 20); btn_habar->setGeometry(620 + extraW, 370 + extraH, 120, 20); btn_vlad->setGeometry(625 + extraW, 410 + extraH, 120, 20); qDebug() << extraW; qDebug() << extraH;}
C++ (Qt)void map::resizeEvent(QResizeEvent *e){ if (this->window()->isVisible()) { QSize ds = e->size() - e->oldSize(); QPoint delta(ds.width(), ds.height()); QWidgetList lst; lst << btn_spb << btn_msc << btn_sev << btn_kalin << murm << btn_rost << btn_ekb << btn_habar << btn_vlad; for (int i = 0; i < lst.size(); ++i) lst[i]->move(lst[i]->pos() + delta); }}
#include "map.h"#include <QTextCodec>#include <QResizeEvent>#include <QDebug>map::map(QWidget *parent) : QWidget(parent){}/*! главная форма */void map::iniMap(){ QTextCodec *codec = QTextCodec::codecForName("CP1251"); QTextCodec::setCodecForTr(codec); QTextCodec::setCodecForCStrings(codec); QTextCodec::setCodecForLocale(codec); setWindowTitle(tr("Карта Российской Федерации")); setMinimumSize(800, 450); resize(800, 450); vblayout = new QVBoxLayout(); scrollArea = new QScrollArea(); scrolVBlayout = new QVBoxLayout; label = new QLabel; vblayout->addWidget(scrollArea); scrollArea->setLayout(scrolVBlayout); scrollArea->setWidget(label); scrollArea->setWidgetResizable(true); setLayout(vblayout); label->setPixmap(QPixmap::fromImage(QImage("map_8000.jpg"))); label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); label->setScaledContents(true); btn_spb = new QPushButton(tr("Санкт-Петербург"), this); btn_spb->setFlat(true); btn_msc = new QPushButton(tr("Москва"), this); btn_msc->setFlat(true); btn_sev = new QPushButton(tr("Севастополь"), this); btn_sev->setFlat(true); btn_kalin = new QPushButton(tr("Калининград"), this); btn_kalin->setFlat(true); btn_murm = new QPushButton(tr("Мурманск"), this); btn_murm->setFlat(true); btn_rost = new QPushButton(tr("Ростов-на-Дону"), this); btn_rost->setFlat(true); btn_ekb = new QPushButton(tr("Екатеринбург"), this); btn_ekb->setFlat(true); btn_habar = new QPushButton(tr("Хабаровск"), this); btn_habar->setFlat(true); btn_vlad = new QPushButton(tr("Владивосток"), this); btn_vlad->setFlat(true); settings = new QSettings("data_map.ini", QSettings::IniFormat); QTextCodec *codec_ini = QTextCodec::codecForName("CP1251"); settings->setIniCodec(codec_ini); connect(btn_spb, SIGNAL(clicked()), SLOT(message_spb())); connect(btn_msc, SIGNAL(clicked()), SLOT(message_msc())); connect(btn_sev, SIGNAL(clicked()), SLOT(message_sev())); connect(btn_kalin, SIGNAL(clicked()), SLOT(message_kalin())); connect(btn_murm, SIGNAL(clicked()), SLOT(message_murm())); connect(btn_rost, SIGNAL(clicked()), SLOT(message_rost())); connect(btn_ekb, SIGNAL(clicked()), SLOT(message_ekb())); connect(btn_habar, SIGNAL(clicked()), SLOT(message_habar())); connect(btn_vlad, SIGNAL(clicked()), SLOT(message_vlad()));}void map::resizeEvent(QResizeEvent *e){ int extraW = width() - minimumWidth(); int extraH = height() - minimumHeight(); btn_spb->setGeometry(100 + extraW, 145 + extraH, 120, 20); btn_msc->setGeometry(65 + extraW, 200 + extraH, 120, 20); btn_sev->setGeometry(0 + extraW, 230 + extraH, 120, 20); btn_kalin->setGeometry(20 + extraW, 110 + extraH, 120, 20); btn_murm->setGeometry(150 + extraW, 80 + extraH, 120, 20); btn_rost->setGeometry(45 + extraW, 260 + extraH, 120, 20); btn_ekb->setGeometry(210 + extraW, 260 + extraH, 120, 20); btn_habar->setGeometry(620 + extraW, 370 + extraH, 120, 20); btn_vlad->setGeometry(625 + extraW, 410 + extraH, 120, 20); qDebug() << extraW; qDebug() << extraH;}void map::message_spb(){ QString city = settings->value("spb").toString(); QMessageBox::information(this, tr("Описание объекта..."), city);}void map::message_msc(){ QString city = settings->value("msc").toString(); QMessageBox::information(this, tr("Описание объекта..."), city);}void map::message_ekb(){ QString city = settings->value("ekb").toString(); QMessageBox::information(this, tr("Описание объекта..."), city);}void map::message_sev(){ QString city = settings->value("sev").toString(); QMessageBox::information(this, tr("Описание объекта..."), city);}void map::message_murm(){ QString city = settings->value("murm").toString(); QMessageBox::information(this, tr("Описание объекта..."), city);}void map::message_kalin(){ QString city = settings->value("kalin").toString(); QMessageBox::information(this, tr("Описание объекта..."), city);}void map::message_rost(){ QString city = settings->value("rost").toString(); QMessageBox::information(this, tr("Описание объекта..."), city);}void map::message_habar(){ QString city = settings->value("habar").toString(); QMessageBox::information(this, tr("Описание объекта..."), city);}void map::message_vlad(){ QString city = settings->value("vlad").toString(); QMessageBox::information(this, tr("Описание объекта..."), city);}map::~map(){ }