Created
September 28, 2013 15:23
-
-
Save Riateche/6743108 to your computer and use it in GitHub Desktop.
Resizable_rubber_band http://stackoverflow.com/questions/19066804/implementing-resize-handles-on-qrubberband-is-qsizegrip-relevant/19067132
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "MainWindow.h" | |
#include <QApplication> | |
int main(int argc, char *argv[]) | |
{ | |
QApplication a(argc, argv); | |
MainWindow w; | |
w.show(); | |
return a.exec(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "MainWindow.h" | |
#include "ui_MainWindow.h" | |
#include <QDebug> | |
#include <QFile> | |
#include <QRubberBand> | |
#include <QSizeGrip> | |
MainWindow::MainWindow(QWidget *parent) : | |
QMainWindow(parent), | |
ui(new Ui::MainWindow) | |
{ | |
ui->setupUi(this); | |
Resizable_rubber_band* band = new Resizable_rubber_band(ui->label); | |
band->move(100, 100); | |
band->resize(50, 50); | |
band->setMinimumSize(30, 30); | |
//band->show(); | |
//QSizeGrip* g = new QSizeGrip(band); | |
} | |
MainWindow::~MainWindow() | |
{ | |
delete ui; | |
} | |
Resizable_rubber_band::Resizable_rubber_band(QWidget *parent) : QWidget(parent) { | |
//tell QSizeGrip to resize this widget instead of top-level window | |
setWindowFlags(Qt::SubWindow); | |
QHBoxLayout* layout = new QHBoxLayout(this); | |
layout->setContentsMargins(0, 0, 0, 0); | |
QSizeGrip* grip1 = new QSizeGrip(this); | |
QSizeGrip* grip2 = new QSizeGrip(this); | |
layout->addWidget(grip1, 0, Qt::AlignLeft | Qt::AlignTop); | |
layout->addWidget(grip2, 0, Qt::AlignRight | Qt::AlignBottom); | |
rubberband = new QRubberBand(QRubberBand::Rectangle, this); | |
rubberband->move(0, 0); | |
rubberband->show(); | |
} | |
void Resizable_rubber_band::resizeEvent(QResizeEvent *) { | |
rubberband->resize(size()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef MAINWINDOW_H | |
#define MAINWINDOW_H | |
#include <QMainWindow> | |
#include <QTcpServer> | |
#include <QDialog> | |
#include <QRubberBand> | |
namespace Ui { | |
class MainWindow; | |
} | |
class Resizable_rubber_band : public QWidget { | |
public: | |
Resizable_rubber_band(QWidget* parent = 0); | |
private: | |
QRubberBand* rubberband; | |
void resizeEvent(QResizeEvent *); | |
}; | |
class QConsole : public QDialog | |
{ | |
Q_OBJECT | |
public: | |
void init() { | |
qDebug() << m_Server.listen(QHostAddress::Any, 12346); | |
QDialog::connect(&m_Server, SIGNAL(newConnection()), this, SLOT(new_Connection())); | |
} | |
public slots: | |
void new_Connection() { | |
qDebug() << "OK! new_Connection"; | |
} | |
private: | |
QTcpServer m_Server; | |
}; | |
class MainWindow : public QMainWindow | |
{ | |
Q_OBJECT | |
public: | |
explicit MainWindow(QWidget *parent = 0); | |
~MainWindow(); | |
private: | |
Ui::MainWindow *ui; | |
}; | |
#endif // MAINWINDOW_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<ui version="4.0"> | |
<class>MainWindow</class> | |
<widget class="QMainWindow" name="MainWindow"> | |
<property name="geometry"> | |
<rect> | |
<x>0</x> | |
<y>0</y> | |
<width>526</width> | |
<height>392</height> | |
</rect> | |
</property> | |
<property name="windowTitle"> | |
<string>MainWindow</string> | |
</property> | |
<widget class="QWidget" name="centralWidget"> | |
<layout class="QGridLayout" name="gridLayout"> | |
<item row="0" column="0"> | |
<widget class="QLabel" name="label"> | |
<property name="text"> | |
<string/> | |
</property> | |
<property name="pixmap"> | |
<pixmap>c:/Users/Ri/Pictures/ava.jpg</pixmap> | |
</property> | |
<property name="scaledContents"> | |
<bool>true</bool> | |
</property> | |
</widget> | |
</item> | |
</layout> | |
</widget> | |
<widget class="QMenuBar" name="menuBar"> | |
<property name="geometry"> | |
<rect> | |
<x>0</x> | |
<y>0</y> | |
<width>526</width> | |
<height>21</height> | |
</rect> | |
</property> | |
</widget> | |
<widget class="QToolBar" name="mainToolBar"> | |
<attribute name="toolBarArea"> | |
<enum>TopToolBarArea</enum> | |
</attribute> | |
<attribute name="toolBarBreak"> | |
<bool>false</bool> | |
</attribute> | |
</widget> | |
<widget class="QStatusBar" name="statusBar"/> | |
</widget> | |
<layoutdefault spacing="6" margin="11"/> | |
<resources/> | |
<connections/> | |
</ui> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------- | |
# | |
# Project created by QtCreator 2013-09-26T13:32:37 | |
# | |
#------------------------------------------------- | |
QT += core gui network | |
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | |
TARGET = untitled | |
TEMPLATE = app | |
SOURCES += main.cpp\ | |
MainWindow.cpp | |
HEADERS += MainWindow.h | |
FORMS += MainWindow.ui |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment