Skip to content

Language Bindings

You're using Qt with other languages than C++, eh? Post here!
853 Topics 3.3k Posts
  • how do i separate these sudoku boxes (grids)

    Unsolved
    4
    0 Votes
    4 Posts
    653 Views
    jazzycamelJ

    @nullbuil7 said in how do i separate these sudoku boxes (grids):

    import sys
    from PySide2.QtWidgets import *
    from PySide2.QtGui import *

    class SudokuGrid(QWidget):
    def init(self):
    super(SudokuGrid, self).init()
    self.initGUI()

    def initGUI(self): self.setWindowTitle("Sudoku Grid Example") self.setGeometry(800, 800, 400, 350) self.setGrid() def setGrid(self): gridLayout = QGridLayout() box1 = QGridLayout() box2 = QGridLayout() box3 = QGridLayout() box4 = QGridLayout() box5 = QGridLayout() box6 = QGridLayout() box7 = QGridLayout() box8 = QGridLayout() box9 = QGridLayout() hline = QFrame() hline.setFrameShape(QFrame.HLine) hline.setFrameShadow(QFrame.Sunken) vline = QFrame() vline.setFrameShape(QFrame.VLine) vline.setFrameShadow(QFrame.Sunken) gridLayout.addLayout(box1,0,0) gridLayout.addWidget(vline, 0, 1) gridLayout.addLayout(box2,0,2) gridLayout.addWidget(vline, 0, 3) gridLayout.addLayout(box3,0,4) gridLayout.addWidget(hline, 1, 0, 1, 5) gridLayout.addLayout(box4,2,0) gridLayout.addWidget(vline, 2, 1) gridLayout.addLayout(box5,2,2) gridLayout.addWidget(vline, 2, 3) gridLayout.addLayout(box6,2,4) gridLayout.addWidget(hline, 3, 0, 1, 5) gridLayout.addLayout(box7,4,0) gridLayout.addWidget(vline, 4, 1) gridLayout.addLayout(box8,4,2) gridLayout.addWidget(vline, 4, 3) gridLayout.addLayout(box9,4,4) pos = [(0,0),(0,1),(0,2), (1,0),(1,1),(1,2), (2,0),(2,1),(2,2)] i = 0 while i < 9: box1.addWidget(QLabel("1", self), pos[i][0], pos[i][1]) box2.addWidget(QLabel("1", self), pos[i][0], pos[i][1]) box3.addWidget(QLabel("1", self), pos[i][0], pos[i][1]) box4.addWidget(QLabel("1", self), pos[i][0], pos[i][1]) box5.addWidget(QLabel("1", self), pos[i][0], pos[i][1]) box6.addWidget(QLabel("1", self), pos[i][0], pos[i][1]) box7.addWidget(QLabel("1", self), pos[i][0], pos[i][1]) box8.addWidget(QLabel("1", self), pos[i][0], pos[i][1]) box9.addWidget(QLabel("1", self), pos[i][0], pos[i][1]) i = i + 1 self.setLayout(gridLayout)

    if name == 'main':
    try:
    myApp = QApplication(sys.argv)
    myWindow = SudokuGrid()
    myWindow.show()
    myApp.exec_()
    sys.exit(0)
    except NameError:
    print("Name Error:", sys.exc_info()[1])
    except SystemExit:
    print("Closing Window...")
    except Exception:
    print(sys.exc_info()[1])

    Its not a bug in Qt or PySide2: you can't add a widget to a layout multiple times; you only create one each ofhline and vline and add them to multiple locations in your layout. See my example below where I create a new instance of hline and vline each time I use them (and tidied things up a bit):

    from PySide2.QtWidgets import QWidget, QGridLayout, QFrame, QLabel class SudokuGrid(QWidget): def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self.setWindowTitle("Sudoku Grid Example") self.setGeometry(800,800,400,350) l=QGridLayout(self) boxes=[] for i in range(9): col=i%3 row=i//3 box=QGridLayout() boxes.append(box) l.addLayout(box, row*2, col*2) if col<2: vline=QFrame() vline.setFrameShape(QFrame.VLine) vline.setFrameShadow(QFrame.Sunken) l.addWidget(vline, row*2, (col*2)+1) if col==2 and row<2: hline=QFrame() hline.setFrameShape(QFrame.HLine) hline.setFrameShadow(QFrame.Sunken) l.addWidget(hline, (row*2)+1, 0, 1, 5) for box in boxes: for i in range(9): col=i%3 row=i//3 box.addWidget(QLabel(str(i),self), row, col) if __name__=="__main__": from sys import argv, exit from PyQt5.QtWidgets import QApplication a=QApplication(argv) s=SudokuGrid() s.show() exit(a.exec_())

    I've tested this with PyQt5 not PySide2, but they are compatible and this code should work perfectly well.

    Hope this helps ;o)

  • setting style in python3/pyside2

    Solved
    2
    0 Votes
    2 Posts
    703 Views
    mrjjM

    Hi
    Should it not be on the application like ?
    QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Fusion'))

  • Attach Debugger to Valgrind PID

    Unsolved
    2
    0 Votes
    2 Posts
    1k Views
    R

    Relating to attaching Debugger to Valgrind PID, when I launch qtcreator

    ./qtcreator

    The following messages appear before launching
    Analyze->Valgrind Memory Analyzer with GDB
    Debug->Attach to Running Application

    QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
    QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
    QXcbShmImage: xcb_shm_attach() failed with error: 10 (BadAccess), sequence: 552, resource id: 311, major code: 130 (Unknown), minor code: 1

  • XML Request rejected

    Unsolved
    2
    0 Votes
    2 Posts
    438 Views
    SGaistS

    Hi,

    What version of Qt are you using ?
    What Linux distribution are you running ?
    What versions of OpenSSL do you have installed ?

    You are not connecting the error related signals anywhere, you should so you'll have more information about what is going wrong.

    On a side note, there's no need to create your QNetworkRequest on the the heap as shown in the QNetworkAccessManager documentation.

  • How to include the Lua library into my Qt project?

    Unsolved
    9
    0 Votes
    9 Posts
    2k Views
    S

    @aha_1980 I will try compiling it myself since I'd like to stick with MinGW.

    Just tried that but MinGW outputs the following:
    0 [main] sh 1816 sync_with_child: child 12536(0x1E4) died before initializing with status code 0xC0000142
    208 [main] sh 1816 sync_with_child: *** child state waiting for longjmp
    /usr/bin/sh: fork: Resource temporarily unavailable
    mingw32-make: *** [Makefile:55: mingw] Error 128

  • how can i list the files in a directory

    Unsolved
    7
    0 Votes
    7 Posts
    3k Views
    JonBJ

    @Nathan-Miguel
    Look, the "dots" aren't part of a file name, they are the . and the .. entries in the directory, The other two are filenames. You are choosing to print them out all touching each other (testlist.join("")). Clearly that has nothing to do with your "want to set to open a file inside the folder". You can access indvidual files via each element in entryList() or entryInfoList(), as you please.

  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    8 Views
    No one has replied
  • 0 Votes
    1 Posts
    461 Views
    No one has replied
  • QPushButton binding does not work without lambda keyword

    Unsolved
    5
    0 Votes
    5 Posts
    718 Views
    SGaistS

    Can you rather post a minimal example that shows that behaviour ?

  • Problem with SetIcon when using a png

    Unsolved
    7
    0 Votes
    7 Posts
    854 Views
    SGaistS

    Because the environment variable is described here. The fact that you are using python is of no importance here.

  • glitch in javascript bindings

    Unsolved
    7
    0 Votes
    7 Posts
    983 Views
    Gojir4G

    @skylendar Sorry, I miss your last message.
    Any improvements here ?

  • Golang TreeView example not working

    Unsolved
    2
    0 Votes
    2 Posts
    889 Views
    mrjjM

    Hi and welcome to the forums
    I dont know Golang but the interface is the same so i would
    check in func (m *CustomTableModel) data
    that this test
    if role != int(core.Qt__DisplayRole) {
    return core.NewQVariant()
    }

    is not always returning an empty variant for each call.

    also
    case 0:
    return core.NewQVariant12(item.firstName)
    case 1:
    return core.NewQVariant12(item.lastName)

    does return a valid QVariant ?

    i wondered why the empty one is
    NewQVariant()
    but with data its NewQVariant12 ?

  • Which is Better C or C++?

    Unsolved
    5
    0 Votes
    5 Posts
    1k Views
    JonBJ

    @Mayankjain
    C is plain better (IMHO) :) But for your career, C++ is definitely more advisable!

  • QAxServer in Python [PySide] [PyQt]

    2
    0 Votes
    2 Posts
    2k Views
    F

    Hello,

    I'm facing the same issue.

    Have you solved this problem?

  • Q_Property add range macros

    Unsolved
    2
    0 Votes
    2 Posts
    614 Views
    SGaistS

    Hi,

    AFAIK, there's none. You need to implement your own macro on top Q_PROPERTY to do that.

  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    9 Views
    No one has replied
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    18 Views
    No one has replied
  • C function as QJSValue

    Unsolved
    5
    0 Votes
    5 Posts
    794 Views
    S

    So I give up. I'll declare a method instead.

    Maybe in a further version of Qt5.

    Thank you anyway.

  • Read a specific tag in xml

    Solved
    8
    0 Votes
    8 Posts
    2k Views
    KroMignonK

    @Nathan-Miguel said in Read a specific tag in xml:

    PROGRAM DIRECTORY: E:\Git\Denoiser-Script\QML_C++\build-Denosier-Desktop_Qt_5_12_3_MSVC2017_64bit2-Debug\debug
    XML DIRECTORY: E:\Git\Denoiser-Script\QML_C++\build-Denosier-Desktop_Qt_5_12_3_MSVC2017_64bit2-Debug\debug\sysinfo\system.xml

    In your code extract you have hard coded the path and with you output it should be:

    QString systeminfo::getCpuName() { QString rootDir = qApp->applicationDirPath(); // QDir::currentPath() != not application path QString xmlDir = "/sysinfo/system.xml"; QDomDocument docxml; QString test; QFile xmlread; xmlread.setFileName(rootDir+xmlDir); test = "head"; if (xmlread.open(QIODevice::ReadOnly)) { QXmlStreamReader reader(&xmlread); if (docxml.setContent(&xmlread)){ //Open xml with success test = "xml loaded with success"; //Read specifc tag xml auto nodes = docxml.elementsByTagName("cpuname"); for(int i = 0; i < nodes.count(); i++) { QDomNode elm = nodes.at(i); if(elm.isElement()) { test = QStringLiteral("%1 = %2").arg(elm.toElement().tagName(), elm.toElement().text()); } } } } return test; }

    ==> my output with this code and your XML document is:
    0_1561445518059_240c2702-943f-4bcc-b78f-e2a3dabc860e-image.png

  • Generating bindings for other languages

    Unsolved
    2
    0 Votes
    2 Posts
    582 Views
    JKSHJ

    Hi @semtexzv, and welcome!

    @semtexzv said in Generating bindings for other languages:

    ...mainly utilize Rust language.

    Have you seen the Rust-Qt project? https://github.com/rust-qt

    could the shiboken generator used to generate bindings for other languages in custom format ?

    I'll leave this question for someone else who has experience with Shiboken. But if you want to check yourself, this is a good place to start: https://blog.qt.io/blog/2018/05/31/write-python-bindings/