How to enable resizing of a frameless widget



  • What to write here:
    @void CropFrame::resizeEvent(QResizeEvent *event)
    {
    //what to write here
    }@



  • Nothing special. That method is called when the widget is already being resized. I guess your problem is how to actually make the widget resizable. By far the easiest way to do that, is to just give the widget a frame and let the window system handle it for you. Otherwise, look into using [[doc:QSizeGrip]].



  • I have already tried QSizeGrip, it is working fine but the issue is that it appears on the top left corner instead of bottom right which is cuasing some specific problem. As per Qt- Doc a frameless window does not support resizing or even dragging. But we can re-implement the mouseMoveEvent and resize events to enable that too. Now, what i want is code for resizing:
    @CropFrame::CropFrame(QLabel *parent) :
    QLabel(parent,Qt::FramelessWindowHint | Qt::SubWindow)
    {
    setStyleSheet("background-color: rgba(0, 0, 0, 40%)");
    sizeGrip=new QSizeGrip(this);

    setPixmap(QPixmap(":/icons/crop_area.png"));
    setScaledContents(true);
    setWindowOpacity(.900);
    setWindowModality(Qt::ApplicationModal);
    setFrameStyle(2);
    

    }

    void CropFrame::mousePressEvent(QMouseEvent *event)
    {
    if (event->button() == Qt::LeftButton) {
    dragPosition = event->globalPos() - frameGeometry().topLeft();
    event->accept();
    }
    }

    void CropFrame::mouseMoveEvent(QMouseEvent *event)
    {
    if (event->buttons() & Qt::LeftButton) {
    move(event->globalPos() - dragPosition);
    topPos=event->globalPos() - dragPosition;
    event->accept();
    }
    }

    void CropFrame::resizeEvent(QResizeEvent *event)
    {
    //what to write here
    }@



  • Is this the same issue as the one you're discussing in "this":/forums/viewthread/16161/ topic?



  • Perhaps, yes. As no one replied to my my query yesterday, I figured out a way myself, but got stuck with other problem. So, i asked this question to completely change the way of resizing. The code is same, but i want to use resizing event as it enables resizing from every side and Qsizegrip allows resizing only from one corner



  • I hope you are not angry



  • You need to practice more patience. Please recognize that it is Easter weekend, and lots of people are enjoying time off with their families. At least have patience until, say Wednessday before you start thinking that your topic is being ignored. It is not good practice to open multiple parallel topics that are really about the same thing in any case.



  • I am sorry, perhaps I should have closed the previous topic , i will be doing now, btw what about resizing?



  • [quote author="adnan" date="1333967014"]What to write here:
    @void CropFrame::resizeEvent(QResizeEvent *event)
    {
    //what to write here
    }@[/quote]

    You need to call resize() or setGeometry() to change the size of your widget.

    resizeEvent() doesn't do such things, this is similer to mousePressEvent() which is called when you press your mouse, but it doesn't press mouse by itself.

    you can call resize() when your mouse pressed --> moved --> released.



  • If we consider any normal widget, just by moving the mouse to the boundary changes the shape of cursor, and we can resize that widget, can't we just restore the same resizing ability with same features of cursor shape change etc. in frameless widgets.
    Besides, i am using mousepressevent for draging
    @void CropFrame::mousePressEvent(QMouseEvent *event)
    {
    if (event->button() == Qt::LeftButton) {
    dragPosition = event->globalPos() - frameGeometry().topLeft();
    event->accept();
    }
    }@

    How will it know, whether it has to resize or drag if i use resize() in mousepressevent



  • [quote author="adnan" date="1333996860"]
    How will it know, whether it has to resize or drag if i use resize() in mousepressevent[/quote]

    It depends on you.

    For example, when you move the mouse to the boundary(close to the boundary but still in your widget),
    which behavior is you wanted. Changes the shape of cursor or not?



  • Alright, i don't wish to lenghten this discussion: QSizeGrip is working fine but has one issue, if you can resolve the issue the story ends here, no need of resizing using resizing event. I don't have much experience in event handling.

    Actually the above Qlabel variant that is CropFrame class, I am using to mark the region for cropping. It is actually for selecting the area for cropping. For cropping i am passing the top left co-ordinates and height and width of CropFrame object. In mousemoveEvent i am storing the top left co-ordinates in @ topPos=event->globalPos() - dragPosition;@
    @void CropFrame::mouseMoveEvent(QMouseEvent *event)
    {
    if (event->buttons() & Qt::LeftButton) {
    move(event->globalPos() - dragPosition);
    topPos=event->globalPos() - dragPosition;
    event->accept();
    }
    }@
    Now suppose i move the cropping rectangle in the middle, topPos is updated as expected, but now if i resize by holding QSizeGrip without moving the crop-rectantgle and increase the dimensions of rectangle, lenght and width are updated but topPos is not updated thereby causing problem. If somehow QSizeGrip appears at bottom right then everything wud be fine as it wud only increase length and width without changing topPos.



  • Anybody plz help! I have to submit my project within 3 days. I don't want to submit my project with above bug.



  • [quote author="adnan" date="1334000971"]Anybody plz help! I have to submit my project within 3 days. I don't want to submit my project with above bug.[/quote]

    Please note that, QLabel is a QWidget, QGripSize is another QWidget.
    one widget can be put any where in another widget.

    In your code, you forget to specify the location of QGripSize.



  • How to specify the the location. I couldn't find any function. There is hardly a one page doc for QsizeGrip in Qt docs



  • You could use a layout, or you reimplement the resizeEvent of your widget to manually position the size grip.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.