Custom QPushButton which can be stretchable and draggable
-
How to create a custom QPushButton which is draggable and stretchable in the ui using QMouseEvent class or any other methods?
-
@Sherlin-N-G Subclass QPushButton and overwrite some events. See http://doc.qt.io/qt-5/qtwidgets-draganddrop-draggableicons-example.html
-
@Sherlin-N-G
Use dock widget
http://doc.qt.io/archives/qt-4.8/qdockwidget.html -
Can you give me a code snippet on how it is used.If you dont mind I'm new to this tool
-
@Sherlin-N-G
Hi
This sample have docks
http://doc.qt.io/qt-5/qtwidgets-mainwindows-dockwidgets-example.html -
@mrjj Thanks for the reply.I tried running the application but I dont know how that is even related to my problem.Please help me understand.
-
@Sherlin-N-G
Hi
Im not sure how either. Docks are windows :)
For resize/move push buttons, this might be more useful
https://wiki.qt.io/Widget-moveable-and-resizeable -
@mrjj Hi,Thanks for the link. I tried the code in the link,but thats creating a widget not a button.I actually want a resizable and movable QPushbutton on which further I'll give signals and slots.
-
@Sherlin-N-G A button is a widget...
-
Hi
The code from link also works with buttons and all widgets.
So just insert QPushButton and it manage that.it create labels
QLabel *lab1 = new QLabel("Label1"); QLabel *lab2 = new QLabel("Label2"); TContainer *con1 = new TContainer(this, QPoint(10, 10), lab1); TContainer *con2 = new TContainer(this, QPoint(20, 50),lab2); }
but you can just use PushButton instead.
You can use a stylesheet to make button look like that.QPushButton { border: 0; background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(255, 239, 224, 255), stop:0.55 rgba(38, 108, 235, 255), stop:0.98 rgba(0, 0, 0, 255), stop:1 rgba(0, 0, 0, 0)); }
-
@Sherlin-N-G
The stylesheet, you can assign to Mainwindow so all pushbuttons are affected.The
TContainer *con1 = new TContainer(this, QPoint(10, 10), lab1);is for the function in your app that inserts new Button on form.
there u would hook it to container for resize/move. -
Hi
The author is
https://wiki.qt.io/Widget-moveable-and-resizeable- Programmer Aleksey Osipov
- email: aliks-os@yandex.ru
But since its just a sample and posted on a wiki i would say its safe to use.