Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Window resizing logic error
Forum Updated to NodeBB v4.3 + New Features

Window resizing logic error

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    joshua-anderson
    wrote on last edited by
    #1

    Hello Everyone,

    I am working to resize a boarderless window in qt, but I am having a strange problem, when I try to resize on the top and the left of the window, my mouse movement is scaled down and movement is very jittery. On the bottom and right, it behaves as expected with normal resizes. I am pretty sure there is a logic error in my code but can't figure out after two days of contemplating figure it out. I write this with qt and c++ but is fairly simple and should be readable to anyone who understands c style computer code.

    My code works by setting a enum of possible sides the mouse can be over, set when the mouse moves over them. When the mouse moves over the edge, the code calls resizeWindow and sets in resize zone to true. When I click the mouse, the mouse sets the coordinates of the press and sets the variable allowToResize to true. When the time comes to resize, the code subtracts the current mouse position from the position of the click position, adds it to the side of the rectangle that you are resizing, and then resets the originional click position with the current clikc position

    I would greatly appreaciate it if anyone can figure out what I overlooked in the code that causes it to behave correctly on some sides and scaled down on the top and left. If you need more of my code just let me know and I will post it. Thanks!!!

    Here is my code:

    @//called when mouse is pressed
    void mainTrackbox::mousePressEvent(QMouseEvent *e)
    {
    if (e->button() == Qt::LeftButton)
    {
    if (inResizeZone)
    {
    offset = e->pos();
    allowToResize = true;
    }
    }
    e->accept();
    }

    //Called when mouse is released
    void mainTrackbox::mouseReleaseEvent(QMouseEvent *e)
    {
    moveWidget = false;
    allowToResize = false;
    resizeDir = none;
    offset = QPoint();

    e->accept();
    

    }

    //Called when mouse is over resize zone, enum set when mouse moves over resize zone as well
    void mainTrackbox::resizeWindow(QMouseEvent *e)
    {
    if(allowToResize) {
    QPoint eventPoint = e->pos();
    QRect geom = this->geometry();
    QPoint diff = eventPoint - offset;

        qDebug() << eventPoint;
        qDebug() << offset;
        qDebug() << diff;
    
        switch (resizeDir) {
        default:
            break;
        case none:
            qDebug() <<"None";
            break;
        case top:
            qDebug() <<  geom.top();
            geom.setTop(geom.top() + diff.y());
            qDebug() <<  geom.top();
            qDebug() <<"Top";
            break;
        case bottom:
            qDebug() <<"Bottom";
            geom.setBottom(geom.bottom() + diff.y());
            break;
        case left:
            qDebug() <<"Left";
            geom.setLeft(geom.left() + diff.x());
            break;
        case right:
            qDebug() <<"Right";
            geom.setRight(geom.right() + diff.x());
            break;
        }
        this->setGeometry(geom);
        offset = eventPoint;
    }
    

    }@

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Don't know exactly and no expert on the paint stuff, but it probably has to do with the fact that all widgets/paintdevices are build from top left to bottom right causing more overhead when shifting those edges. On the other hand it should be possible to do so. Maybe increase your diff value to a higher threshold before redrawing. Let's say that you only redraw every 15 pixels? Just a thought ;-)

      Greetz, Jeroen

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        fixed in your "initial thread":http://qt-project.org/forums/viewthread/31246/.
        Nevertheless you wont be able to eliminate the jumping when resizing top/left edges since there is also an (event-based) moving of the window involved...

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved